-
September 14th, 2013, 03:28 PM
#1
Error while using cin.get
Hi, Line 76: cin.get(g.handicap+count);
Pre compile error dot in between cin and get. no instance of overload function ...
Code:
// golf.h -- for pe-9.cpp
const int Len = 40;
struct golf
{
char fullname[Len];
int handicap;
};
//non-interactive version:
// function sets golf structure to provided name, handicap
// using vlues passed as arguments to the function
void setgolf(golf & g, const char * name, int hc);
// interactive version:
// function name and handicap from user
// and sets the members of g to the values entered
// returns 1 if name is entered, 0 if name is empty string
int setgolf(golf & g);
// function resets handicap to new value
void handicap(golf & g, int hc);
// function displays contents of golf structure
void showgolf(const golf & g);
// chapEx9-1
#include <iostream>
#include "golf.h"
using namespace std;
int main()
{
golf ann;
setgolf(ann, "Ann Birdfree", 24);
showgolf(ann);
cout << "Enter how many golfers name and handicap do you want to enter: ";
int ngolfers;
cin >> ngolfers;
while (cin.get() != '\n')
continue;
golf * ptr_golf = new golf[ngolfers];
//int entered = getinfo
int rint = 1;
while (rint == 1)
rint = setgolf(ptr_golf);
showgolf(ann);
}
// golf.cpp load and show golf struc
#include<iostream>
#include "golf.h"
using namespace std;
void setgolf(golf & g, const char * name, int hc)
{
strcpy_s(g.fullname, name);
g.handicap = hc;
// strlen(name)
}
int setgolf(golf & g)
{
static int count = 1;
static int pos = 0;
char fname[40];
cout << "Enter golfers name: ";
cin.getline(g.fullname+count, 40, '\n');
cout << "Enter golfers handicap: ";
cin.get(g.handicap+count);
cin.get();
++count;
if (strlen(g.fullname) == 0)
return 0;
else
return 1;
}
void showgolf(const golf & g)
{
cout << "\nFull name: " << g.fullname << "\n";
cout << "Handicap: " << g.handicap << "\n";
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|