-
May 14th, 2010, 01:00 AM
#1
Need Help FAST!!!
I am a programming student who requires help. I've asked what other students I could and I couldn't get help from them. I need to complete this and I keep getting errors. My program isn't running properly. Here is my code and if someone could help soon that would be great. THANK YOU!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string guess[5];
int counter;
int choice;
int name;
int hint;
counter = 0; counter++;
ifstream infile;
ofstream outfile;
infile.open("Guess.txt");
infile >> guess[5];
cout << "This is an Animal Guessing Game." << endl;
cout << "After each guess you get a clue as to what the animal is." << endl;
infile.close();
outfile.open("Guess.txt");
outfile << guess[5];
outfile.close();
while (counter < 5)
{
cout << "What animal am I?" << hint[counter] << endl;
cin >> guess;
counter++;
if (counter == 5);
cout << "Sorry I am a frog." << endl;
cout << "Play again? <y> or <n> " << endl;
cin >> choice;
switch (choice)
{
case 'y/Y':
cout << "This is an Animal Guessing Game." << endl;
counter++;
case 'n/N':
cout << "Thank you for playing. Goodbye." << endl;
default:
cout << "Illegal letter, please try again." << endl;
}
}
return 0;
}
-
May 14th, 2010, 05:48 AM
#2
Re: Need Help FAST!!!
Please use tags for ur code
-
May 14th, 2010, 06:23 AM
#3
Re: Need Help FAST!!!
Do we need to guess for the errors ?
Code:
counter = 0; counter++;
You set it to 0 and immediately you add 1. Why not set it to 1 the first time ?
Code:
infile >> guess[5];
Your array contains 5 elements, but a array is 0-based (from 0 to 4), so there is no element '5'.
Code:
cout << "What animal am I?" << hint[counter] << endl;
'hint' is not a array.
'choice' is not a character, it's a number (int).
Because there is a ; at the end, this if doesn't do anything at all.
A case statement can only test 1 char. Not 3 as you are trying here. Also a case statement needs a 'break' somewhere or else it will continue with the next case.
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
|