Super Simple Program

So I have some of the basics down now and I just am a little stuck. So right now I have it so it prompts the user for there score, then user then enters a random score and now I need to be able to print out "You got a perfect score!" if they enter 100. I was thinking I should somehow compare whatever they entered with 100 using == or < but I haven't found a way. I know this is a really simple program but I am just starting. Any hints on what to do? Thanks guys! :)

Also if you see anything that can be improved in the code please let me know because I am just starting!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

using namespace std;

int main()
 {
    string mystr;
    cout << "Enter your score:";
    getline (cin, mystr);
    cout << "Your score is:" << mystr << endl;

 }
Last edited on
Hi,

instead of the string type, I would use an integer type to hold the entered value.
And instead of the getline, I would just use cin.

Then you just use an if...else statement to compare the entered value, and print the message accordingly.

1
2
3
4
5
6
7
8
int num = 0;
cout << "Enter your score: ";
cin >> num;

if (entered value == 100)
    print "You got a perfect score!"
else
    print "Your score is:"...

Thank you! Print isn't used in c++ I don't think so I just switched that with cout and it worked great! I appreciate the help :)
Topic archived. No new replies allowed.