3rd Programming Assignment

I just started learning c++ 2 weeks ago, and it is my first programming language. I'm taking an intro to programming class online, so, you, the internet are my designated teacher/s. ^^

I am using Dev C++ compiler and my syntax skills are not very sharp yet, I have an error in line 29 stating, "29 expected `;' before "while" ". I have put a semicolon in every godforsaken line and space of this project and have yet to find a solution... Halp. Please.

// Start
// Declarations
// number numberToGuess
// number myGuess;
//
// numberToGuess = 92
// while myGuess != numberToGuess
// output "Please guess an integer number between 1 and 100"
// input myGuess
// if (myGuess == numberToGuess)
// output "You guessed the correct number"
// else
// output "The number you guessed was incorrect. Try again!"
// end if
// end while
// output "Thanks for playing the guessing game. Have a great day!"
// Stop
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
//Declarations
int numberToGuess;
int numbermyGuess;

numberToGuess=92
while (myGuess!= numberToGuess)
{
cout<<"Please guess an integer number between 1 and 100";
cin>>myGuess;
if (myGuess == numberToguess);
{
cout<<"You guessed the correct number!";
}
else
{
cout<<"The number you guessed was incorrect. Try again!";
}
end if;
}
cout<<"Thanks for playing the guessing game. Have a great day!";
system("PAUSE");
return 0;
}
lol you're missing a ; after the number 92.
Errrr. When I put it there I go from 1 error, to 7... Here's my new error log.

29 `myGuess' undeclared (first use this function)
37 expected primary-expression before "else"
37 expected `;' before "else"
41 `end' undeclared (first use this function)
41 expected `;' before "if"
end if; is not something we use in C++.
Thanks! My c++ book for school is very vague, sadly. I got the program working. Thank you guys again for helping. Here is my WORKING code now. =)

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
//Declarations
int numberToGuess;
int myGuess;

numberToGuess=92;
while (myGuess!= numberToGuess)
{
cout<<"Please guess an integer number between 1 and 100"<<endl;
cin>>myGuess;
if (myGuess == numberToGuess)
{
cout<<"You guessed the correct number!"<<endl;
}
else
{
cout<<"The number you guessed was incorrect. Try again!"<<endl;
}

}
cout<<"Thanks for playing the guessing game. Have a great day!"<<endl;
system("PAUSE");

return 0;
}

Can you figure out how to make the program say whether the user's guess is high or low - it's a bit tough to play at the moment. And can you limit the number of guesses the play can have?

Also, could you use code tags ( the <> button on the right) - it make the code easier to read as it is formatted properly.

Good Luck !!

Edit:
Do you need these?

1
2
#include <cstdlib>
#include <string> 
Last edited on
I can't mess around with that program at the moment, but I will in the near future. I am very curious about how to use the code tag button though. I don't know what to do with the two boxes that pop up. Lastly, I don't actually know if I need to include the <cstdlib> and the <string>. I was just copying examples out of my book... v.v From what I understand I need the cstdlib so the compiler will understand cout,cin,etc... Is that wrong?
Last edited on
Topic archived. No new replies allowed.