NEED HELP! asap! PLEASE

Hi! This is my first (and last) computer science class and I am SO lost. We're suppose to copy and paste this into C++ and fix all the errors and run it. If it runs, we pass and if it doesnt, we fail. I have been sitting here for 4 hours trying to fix the errors but each one i fix, the line above it turns red and I have no idea what i am doing.... Here is the assignment. If anyone can tell me what im doing wrong, I would appreciate it!


/* CSCI 1205: Homework #1
* Student ID: __________________ */
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int secret_number, guess, count;
cout << "Let's play a guessing game!" << endl << endl;
cout << "I'll pick a number from 0 to 9, inclusive." << endl;
cout << "You have up to 9 tries to guess it." << endl;
cout << "Good luck!" << endl << endl;
// rand() returns an integer between 0 and RAND_MAX
// we use modulo, to reduce the scale to 0 .. 9
secret_number = rand() % 10;
count = 0;
do {
if ( count )
cout << "Sorry, that's not it!" << endl;
cout << "Enter your guess: ";
cin >> guess;
} while ( guess != secret_number ) && ( ++count < 9 ) );
// we need this b/c of the "short-circuit" boolean expression
count++;
// we want some space between the guessing and the final result
cout << endl;
if ( guess == secret_number )
{
cout << "You got it in " << count << " guesses!" < endl;
cout << "Good work!" << endl;
}
else
{
cout << "Sorry, you used up all your guesses!" << endl;
cout << "The secret number was: " << secret_number << endl;
cout << "Better luck next time!" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
// END of Homework #0
Here i fixed most theres just one error left i cant figure it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
int secret_number, guess, count;
cout << "Let's play a guessing game!" << endl << endl;
cout << "I'll pick a number from 0 to 9, inclusive." << endl;
cout << "You have up to 9 tries to guess it." << endl;
cout << "Good luck!" << endl << endl;
// rand() returns an integer between 0 and RAND_MAX
// we use modulo, to reduce the scale to 0 .. 9
secret_number = rand() % 10;
count = 0;
do {
if ( count )
cout << "Sorry, that's not it!" << endl;
cout << "Enter your guess: ";
cin >> guess;
} while (( guess != secret_number ) && ( ++count < 9 ));
// we need this b/c of the "short-circuit" boolean expression
count++;
// we want some space between the guessing and the final result
cout << endl;
if(guess == secret_number)
{
cout << "You got it in " << count << " guesses!" < endl;
cout << "Good work!" << endl;
}
else
{
cout << "Sorry, you used up all your guesses!" << endl;
cout << "The secret number was: " << secret_number << endl;
cout << "Better luck next time!" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
it's got compiled in my PC... you just forgot "<" in line no 28.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int main(int argc, char *argv[])
{
    int secret_number, guess, count;
    cout << "Let's play a guessing game!" << endl << endl;
    cout << "I'll pick a number from 0 to 9, inclusive." << endl;
    cout << "You have up to 9 tries to guess it." << endl;
    cout << "Good luck!" << endl << endl;
    // rand() returns an integer between 0 and RAND_MAX
    // we use modulo, to reduce the scale to 0 .. 9
    secret_number = rand() % 10;
    count = 0;
    do 
    {
        if ( count )
        cout << "Sorry, that's not it!" << endl;
        cout << "Enter your guess: ";
        cin >> guess;
    } while (( guess != secret_number ) && ( ++count < 9 ));
    // we need this b/c of the "short-circuit" boolean expression
    count++;
    // we want some space between the guessing and the final result
    cout << endl;
    if(guess == secret_number)
    {
        cout << "You got it in " << count << " guesses!" << endl;
        cout << "Good work!" << endl;
    }
    else
    {
        cout << "Sorry, you used up all your guesses!" << endl;
        cout << "The secret number was: " << secret_number << endl;
        cout << "Better luck next time!" << endl;
    }
    system("PAUSE");
return EXIT_SUCCESS;
}
Ah yes what HiteshVaghani1 said, i cant believe i didnt see that, so here is the full code that compiles

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
int secret_number, guess, count;
cout << "Let's play a guessing game!" << endl << endl;
cout << "I'll pick a number from 0 to 9, inclusive." << endl;
cout << "You have up to 9 tries to guess it." << endl;
cout << "Good luck!" << endl << endl;
// rand() returns an integer between 0 and RAND_MAX
// we use modulo, to reduce the scale to 0 .. 9
secret_number = rand() % 10;
count = 0;
do {
if ( count )
cout << "Sorry, that's not it!" << endl;
cout << "Enter your guess: ";
cin >> guess;
} while (( guess != secret_number ) && ( ++count < 9 ));
// we need this b/c of the "short-circuit" boolean expression
count++;
// we want some space between the guessing and the final result
cout << endl;
if(guess == secret_number)
{
cout << "You got it in " << count << " guesses!" << endl;
cout << "Good work!" << endl;
}
else
{
cout << "Sorry, you used up all your guesses!" << endl;
cout << "The secret number was: " << secret_number << endl;
cout << "Better luck next time!" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.