C++ Quincy beginner code question

I am having a hard time creating a code for this:
If TEST score is less than 80, then increase TEST score by 5; else increase TEST score by 7%. This is what I came up with, please advise as to what changes to make to have a successful outcome.


#include <iomanip>
using namespace std;

int main()
{
int test;
int addFive=5;
int addSeven=.07;

if(test<80)
cout<<"Enter your grade: ";
cin>>test>>addFive;
test = test + addFive;
else
cout=test * addSeven;
return 0
}


You didn't set the variable test and then you try to check if it's less than 80. Ask user for test before you check the value.

You don't need to get user's input for the variable addFive since it's already initialized to 5.

Pseudocode would be
> Ask user for test grade
> If greater than 80 add 5
> Else increase by 7%
Last edited on
If more than one statement add curly braces: http://www.cplusplus.com/doc/tutorial/control/
Also return 0 needs a semicolon

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

 #include <iomanip>
 using namespace std;

int main()
 {
 int test;
 int addFive=5;
 int addSeven=.07;

 if(test<80)
{
 cout<<"Enter your grade: ";
 cin>>test>>addFive;
 test = test + addFive;
}
 else 
 cout=test * addSeven;
 return 0;
 }


Last edited on
To give you an idea...

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
#include <iostream>

int main()
{
	const int addFive{ 5 };
	const double addSevenPerc{ 0.07 };

	std::cout << "Enter your grade: ";
	double testScore{ 0.0 };
	std::cin >> testScore;

	if (testScore < 80)
	{
		testScore += addFive;
		std::cout << "The new grade is " << testScore
			<< " \n";
	}
	else
	{
		testScore += (testScore * addSevenPerc);
		std::cout << "The new grade is " << testScore
			<< " \n";
	}

	return 0;
}
Topic archived. No new replies allowed.