Why does the Program loop

Hello, I need help with the following code. I was checking the first task to see if it would work as intended, but after I enter my name the program just loops to infinity. I would like to know what I can do to solve this problem

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
 #include <iostream>
#include <iomanip>
#include <string>
#include <time.h>

using namespace std; 
 
int main (int argc, char* argv)  
{        
	
string studentName;
char currentDate[10];
_strdate(currentDate);
string date(currentDate);
char main;
int loop;
char letterGrade;
double testPercentage;
double projectPercentage;
double labPercentage;
double homeworkPercentage;
double quizPercentage;
double percentage;
double quizOne, quizTwo, quizThree, quizFour, quizFive, quizSix, quizSeven;   // Yes, I know there is an easier way to do this, but this is easier to keep track of
double homeworkOne, homeworkTwo, homeworkThree, homeworkFour, homeworkFive, homeworkSix, homeworkSeven, homeworkEight, homeworkNine, homeworkTen;
double labOne, labTwo, labThree, labFour, labFive, labSix;
double project;
double testOne, testTwo, testThree;
double total;


bool done = false;
while (!done)
{
cout << "Please Input the number corresponding to the task you want to run" << endl;	
cout << "1: Grading one student from keyboard" << endl;
cout << "2: Grading* whole class from file" << endl;
cout << "3: Generating the grade report of class" << endl;
cout << "Input: ";
cin >> main;

if (main == '1')
{
cout << "Enter Your name: ";
cin >> studentName;

cout << "Enter the grade of your Quizes (? of 5) ";
cin >> quizOne >> quizTwo >> quizThree >> quizFour >> quizFive >> quizSix >> quizSeven;

cout << "Enter the grade of your Homeworks (? of 10): ";
cin >> homeworkOne >> homeworkTwo >> homeworkThree >> homeworkFour >> homeworkFive >> homeworkSix >> homeworkSeven >> homeworkEight >> homeworkNine >> homeworkTen;

cout << "Enter the grade of Lab1 (? of 30): ";
cin >> labOne >> labTwo >> labThree >> labFour >> labFive >> labSix;

cout << "Enter the grade of your Project (? of 80): ";
cin >> project;

cout << "Enter the grade of your Tests (? of 100): ";
cin >> testOne >> testTwo >> testThree;

cout << setw(10) << "NAME" << setw(30) << "TOTAL" << setw(40) << "PERCENTAGE" << setw(50) << "LETTER GRADE" << endl;

total= quizOne+quizTwo+quizThree+quizFour+quizFive+quizSix+quizSeven+homeworkOne+homeworkTwo+homeworkThree+homeworkFour+homeworkFive+homeworkSix+homeworkSeven+homeworkEight+homeworkNine+homeworkTen+labOne+labTwo+labThree+labFour+labFive+labSix+project+testOne+testTwo+testThree;

quizPercentage= quizOne+quizTwo+quizThree+quizFour+quizFive+quizSix+quizSeven*20/7;
homeworkPercentage= homeworkOne+homeworkTwo+homeworkThree+homeworkFour+homeworkFive+homeworkSix+homeworkSeven+homeworkEight+homeworkNine+homeworkTen;
labPercentage= labOne+labTwo+labThree+labFour+labFive+labSix*3.3/6;
projectPercentage= project*1.25;
testPercentage= testOne+testTwo+testThree/3;

percentage= quizPercentage+homeworkPercentage+labPercentage+projectPercentage+testPercentage/5;

if (percentage >= 90)
{
	letterGrade = 'A';
}
else if (percentage >= 80 || percentage <= 89)
{
    letterGrade = 'B';
}
else if (percentage >= 70 || percentage <= 79)
{
	letterGrade = 'C';
}
else if (percentage >= 60 || percentage <= 69)
{
	letterGrade = 'D';
}
else 
{
    letterGrade = 'F';
}

cout << "Student  " << studentName << setw(30) << total << setw(40) << percentage << setw(50) << letterGrade;

}
else if (main == '2') 
{


}
else if (main == '3')
{


}
else

cout << "That is not a correct choice" << endl;


cout << "Do you wish to loop through the program again? (Y/N): ";
cin >> loop;

if( loop == 'N' || loop == 'n')
 done = true;
 cout << "See ya later! \n";

}
 system("pause");
 return 0;
}
loop is an integer type. The letters y and n are not integers. Trying to stuff letters into a number results in the stream entering a failure state which means all subsequent operations on the stream also fail until the failure state is cleared.

Don't try to stuff letters into a number.

Also: Indent your code.
Last edited on
Topic archived. No new replies allowed.