Problem with IF/ELSE Project!

Having trouble with a project I'm working on. Here are the project details..

Problem: DESIGN and COMPLETE a program ACCORDINGLY that determines final letter grade for a student with encouraging comment. Three exams and two assignment scores as well as the student name will be entered by the user. Every score should range from 0.00 – 100.00. The program will give user only one chance to correct invalid score and provide meaningful feedback. Exams and assignments have equal weights for the final score (i.e. 50% by each category) that determines the final grade.

So when I run the program, every thing works fine, I just can't get it to move to the next portion of the program (displaying everything after getting value of assignment 2). I'm sure I made my if statements in a very roundabout way but I can't seem to get it to run past getting all the input values.

If any more information is required, let me know and I'll provide it.


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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	// Declaring Variables
	string studentName;
	double exam_1, exam_2, exam_3, assign_1, assign_2;
	double subtotal_Exam, subtotal_Assign;
	double weighted_Exam, weighted_Assign;
	double total;
	char grade;


	// Storing user's input for student name into string studentName
	cout << "Please enter student name (First, Last): ";
	getline(cin, studentName);
	
	// Displaying message notifying user of the proper format for inputting scores
	cout << "****************************NOTE****************************" << endl;
	cout << "***      Be sure to include decimal point for scores.    ***" << endl;
	cout << "***                                                      ***" << endl;
	cout << "***  !!! All scores should range from 0.00 to 100.00 !!! ***" << endl;
	cout << "***                                                      ***" << endl;
	cout << "***      For example : 80.50 or 73.97                    ***" << endl;
	cout << "****************************NOTE**************************** \n" << endl;
	
	// Storing user's grade for exam 1
	cout << "Please enter score for Exam 1 <EX. 0.00-100.00>: ";
	cin >> exam_1;
	
	if (exam_1 < 0 || exam_1 > 100.00) // If statement to see if exam 1 grade is within valid range: if so, moves to input for exam 2. if not then asks user to enter valid score.
	{
		cout << "Invalid exam score, stay within 0.00 - 100.00 range. Re-enter score for Exam 1: ";
		cin >> exam_1;

		if (exam_1 < 0 || exam_1 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
		{
			cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
			cout << "carefully!" << endl;
			//return 0;
		}

	}
	// Storing user's grade for exam 2
	cout << "Please enter score for Exam 2 <EX. 0.00-100.00>: ";
	cin >> exam_2;

	if (exam_2 < 0 || exam_2 > 100.00) // If statement to see if exam 2 grade is within valid range: if so, moves to input for exam 3. if not then asks user to enter valid score.
	{
		cout << "Invalid exam score, stay within 0.00 - 100.00 range. Re-enter score for Exam 2: ";
		cin >> exam_2;

		if (exam_2 < 0 || exam_2 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
		{
			cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
			cout << "carefully!" << endl;
			//return 0;
		}

	}
	// Storing user's grade for exam 3
	cout << "Please enter score for Exam 3 <EX. 0.00-100.00>: ";
	cin >> exam_3;

	if (exam_3 < 0 || exam_3 > 100.00) // If statement to see if exam 3 grade is within valid range: if so, moves to input for assignment 1. if not then asks user to enter valid score.
	{
		cout << "Invalid exam score, stay within 0.00 - 100.00 range. Re-enter score for Exam 3: ";
		cin >> exam_3;

		if (exam_3 < 0 || exam_3 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
		{
			cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
			cout << "carefully!" << endl;
			//return 0;
		}

	}
	// Storing user's grade for assignment 1
	cout << "Please enter score for Assignment 1 <EX. 0.00-100.00>: ";
	cin >> assign_1;

	if (assign_1 < 0 || assign_1 > 100.00) // If statement to see if assign_1 grade is within valid range: if so, moves to input for assignment 2. if not then asks user to enter valid score.
	{
		cout << "Invald assignment score, stay within 0 - 100.00 range. Re-enter score " << endl;
		cout << "for Assignment 1: ";
		cin >> assign_1;

		if (assign_1 < 0 || assign_1 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
		{
			cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
			cout << "carefully!" << endl;
			//return 0;
		}
	}
	// Storing user's grade for assignment 2
	cout << "Please enter score for Assignment 2 <EX. 0.00-100.00>: ";
	cin >> assign_2;

	if (assign_2 < 0 || assign_2 > 100.00) // If statement to see if assign_2 grade is within valid range: if so, moves to student overview. if not then asks user to enter valid score.
	{
		cout << "Invald assignment score, stay within 0 - 100.00 range. Re-enter score " << endl;
		cout << "for Assignment 2: ";
		cin >> assign_2;

		if (assign_2 < 0 || assign_2 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
		{
			cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
			cout << "carefully! \n" << endl;
			//return 0;
		}
	}

	// Calculating subtotal of grades, weighted score of grades, and total score.
	subtotal_Exam = exam_1 + exam_2 + exam_3;
	subtotal_Assign = assign_1 + assign_2;
	weighted_Exam = (subtotal_Exam * 50) / 300;
	weighted_Assign = (subtotal_Assign * 50) / 200;
	total = weighted_Exam + weighted_Assign;
		
	cout << "---------------------STUDENT OVERVIEW---------------------" << endl;
	cout << " Student name: " << student_Name << endl;
	cout << "                                                     Exams        Assignments \n" << endl;
	cout << setprecision(2) << fixed;
	cout << "1. " << setw(50) << exam_1 << setw(16) << assign_1 << endl;
	cout << "2. " << setw(50) << exam_2 << setw(16) << assign_2 << endl;
	cout << "3. " << setw(50) << exam_3 << "\n" << endl;
	
	cout << "Subtotal " << setw(44) << subtotal_Exam << setw(16) << subtotal_Assign << endl;
	cout << "Weighted Score " << setw(38) << weighted_Exam << setw(16) << weighted_Assign << "\n" << endl;

	cout << "Total " << setw(47) << total << endl;

		
		
		
		
		return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Storing user's grade for exam 1
cout << "Please enter score for Exam 1 <EX. 0.00-100.00>: ";
cin >> exam_1;
    
if (exam_1 < 0 || exam_1 > 100.00) // If statement to see if exam 1 grade is within valid range: if so, moves to input for exam 2. if not then asks user to enter valid score.
{
    cout << "Invalid exam score, stay within 0.00 - 100.00 range. Re-enter score for Exam 1: ";
    cin >> exam_1;

    if (exam_1 < 0 || exam_1 > 100.00) // Nested if statement to see if re-entered grade is valid, if not program notifies user and will end on next key press
    {
            cout << "Invalid input entered. PROGRAM WILL END. Restart program and follow directions " << endl;
            cout << "carefully!" << endl;
            //return 0;
    }

}

Instead of copy-pasting the same code a few times, use a function?
Also, it may be easier store the scores in an array or a vector.
Last edited on
Topic archived. No new replies allowed.