if/else problems. Or am I setting this up correctly?

Hi. I am having difficulty understanding exactly how my instructor wants this set up. I have my c++ book, but even with that, it's very difficult incorporating all of what the book wrote, with the different things he wants. So, from reading the instructions and looking at my code, can anyone tell me if I am setting this up ok? Any advice with the if/else statements? Thanks.

Topics



Branches

if statement

if/else statement



Description



Write a program that will determine whether the user passed or failed a test. The program will ask the user to input the following:



Percent Pass Score

This represents the minimum percent scores required to pass the test.



Maximum Test Score

This represents the maximum total scores in the test.



User Test Score

This represents the actual scores obtained by the user in the test.



From the above input values, the program will compute the user percent scores in the test. It will compare the percent user score with the percent pass score. If the user percent score is equal to or greater than the percent pass score, the program will consider the user having passed the test. Otherwise, the program will consider the user having failed the test. At the end, the program will display the result summary. See the Test section below.



Testing



Input Test Run 1

(User input is shown in bold)



Enter Percent Pass Score:

80

Enter Maximum Test Score:

400

Enter User Test Score:

324



Output Test Run 1



Result Summary



Maximum Score = 400

User Test Score = 324

User Percent Score = 81.0%

Percent Pass Score = 80.0%

Test Result = Passed



Input Test Run 2

(User input is shown in bold)



Enter Percent Pass Score:

80

Enter Maximum Test Score:

400

Enter User Test Score:

316







Output Test Run 2



Result Summary



Maximum Score = 400

User Test Score = 316

User Percent Score = 79.0%

Percent Pass Score = 80.0%

Test Result = Failed





Implementation



Discussion



Operators:

Arithmetic operators

+ - * / %

operands: int (all), char (+, -), double (+, -, *, /)

Arithmetic expression: evaluates to int/double/char

Compare Operators

<, >, == , !=, >=, <=

operands: int, double, char

Compare expressions: Evaluates to boolean type.

Logical Operators

||, &&, !

operands: boolean

Logical Expressions: Evaluates To boolean type.

Assignment Operator

=

Variable on LHS and expression on RHS

LHS (variable) = RHS (expression)

Evalutes right to left.

Operands

Assignment Expression;


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>

using namespace std;

int main()
{
    const double PERCENT_PASS_SCORE = 80,
                MAXIMUM_TEST_SCORE = 400;
            
                
    double int userPercentScore,
                userTestScore = 0;
    
    userPercentScore == MAXIMUM_TEST_SCORE / userTestScore;

        if(PERCENT_PASS_SCORE>=userPercentScore)
            
            
            
            else 
                
        {
            
        }
    return 0;
}
Ok, here is an update. I suppose I'm still confused on how to alter the "test result" without making it a constant. Or at least that's what the professor is asking for. Heres the updated code that I'm still having problems with.

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
40
41
42
#include <iostream>

using namespace std;

int main()
{

double     PERCENTPASSSCORE;
  double          MAXIMUMTESTSCORE;
    double        userTestScore;
         double   userPercentScore;


            cout << "Enter Percent Pass Score: "<<endl;
            cin >> PERCENTPASSSCORE >>endl;

            cout << "Enter Maximum Test Score: "<<endl;
            cin >> MAXIMUMTESTSCORE >>endl;

            cout << "Enter User Test Score: " <<endl;
            cin >> userTestScore >>endl;

            userPercentScore = MAXIMUMTESTSCORE/userTestScore * 100%

            if (PERCENTPASSSCORE>=80%&&TestResult==passed)

            else (PERCENTPASSSCORE<=80%&&TestResult==failed)

            cout << "Result Summary" <<endl;

            cout << "Maximum Score: " << MAXIMUMTESTSCORE <<endl;
            cout << "User Test Score: " << userTestScore <<endl;
            cout << "User Percent Score: " << userPercentScore <<endl;
            cout << "Percent Pass Score: " << PERCENTPASSSCORE << endl;

            cout << "Test Result: " << TestResult <<endl;




    return 0;
}
This is working solution. If you have any questions to how this works feel free to ask

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

int main()
{

		 double PERCENTPASSSCORE;
		 double MAXIMUMTESTSCORE;
		 double userTestScore;             
                 double userPercentScore;
		 short p;                        


            cout << "Enter Percent Pass Score: ";
            cin >> PERCENTPASSSCORE;
			cout << endl;

            cout << "Enter Maximum Test Score: ";      
            cin >> MAXIMUMTESTSCORE;
			cout << endl;

            cout << "Enter User Test Score: ";
            cin >> userTestScore;
			cout << endl;

            userPercentScore = userTestScore/MAXIMUMTESTSCORE * 100;    

            if (userPercentScore >= PERCENTPASSSCORE)                   
			{
				p = 1;
			}

            else 
			{
				p = 2;
			}

            cout << "Result Summary" <<endl;
			
            cout << "Maximum Score: " << MAXIMUMTESTSCORE <<endl;
            cout << "User Test Score: " << userTestScore <<endl;
			cout << fixed << setprecision(2);
            cout << "User Percent Score: " << userPercentScore << "%" << endl;
            cout << "Percent Pass Score: " << PERCENTPASSSCORE << "%"<<  endl;

            if (p == 1)
			{
				cout << "Test result: Passed" << endl;
			}
			else
			{
				cout << "Test result: Failed" << endl;
			}


    getch();
    return 0;
}
Last edited on
Topic archived. No new replies allowed.