Need Help FAST!!!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Need Help FAST!!!

  1. #1
    Join Date
    May 2010
    Posts
    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;
    }

  2. #2
    Join Date
    Apr 2010
    Location
    UK
    Posts
    149

    Re: Need Help FAST!!!

    Please use tags for ur code

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    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.

    Code:
    cin >> choice;
    'choice' is not a character, it's a number (int).

    Code:
    if (counter == 5);
    Because there is a ; at the end, this if doesn't do anything at all.

    Code:
    case 'y/Y':
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center