i cannot stop my looping

guys im having problem with my looping ,its unstoppable

//To calculate average of exam mark 1 and 2 and display status under department

#include <iostream>
using namespace std;

int main()
{

int average;
double mark1, mark2;
char department;
char choose;
char operand;

{
do{
repeat:

cout<<"\nPlease select your department \n";
cout<<"********************************\n";
cout<<"1-jtmk\n";
cout<<"2-jmsk\n";
cout<<"3-quit\n";
cin>>choose;

switch (choose)
{

case '1':
//To calculate average of exam mark 1 and 2 and display status for jtmk department
cout<<"\nYou choose "<< choose <<" for jtmk\n";

cout<<"Please enter your mark1\n:";
cin>>mark1 ;
cout<<"Please enter your mark2\n:";
cin>>mark2 ;
average=(mark1+mark2) /2;
if (average<=40)
cout<<"\nYour average is "<<average<<"\n""You are FAIILED and your status is GAGAL\n\n " ;
else if (average>=40 && average <=60)
cout<<"\nYour average is "<<average<<"\n""You are PASS and Your status is LULUS\n\n ";
else if (average>=60 && average <=80)
cout<<"\nYour average is "<<average<<"\n""You are GOOD and your status is BAGUS\n\n";
else if (average>80 && average<=90)
cout<<"\nYour average is "<<average<<"\n""You are VERY GOOD and your status is CEMERLANG\n\n ";
else
cout<<"\nYour average is "<<average<<"\n""You are BRILLIANT and your status is GEMILANG\n\n";

break;

case '2':
//To calculate average of exam mark 1 and 2 and display status for jmsk department
cout<<"\nYou choose "<< choose<<" for jmsk\n : ";

cout<<"Please enter your mark1\n :";
cin>>mark1 ;
cout<<"Please enter your mark2\n :";
cin>>mark2 ;
average=(mark1+mark2)/2;
if (average<=40)
cout<<"\nYour average is "<<average<<"\n""You are FAIILED and Your status is GAGAL\n\n " ;
else if (average>=40 && average <=50)
cout<<"\nYour average is "<<average<<"\n""You are PASS and Your status is LULUS\n\n ";
else if (average>50 && average <=70)
cout<<"\nYour average is "<<average<<"\n""You are GOOD and your status is SO BAGUS\n\n";
else if (average>70 && average<=85)
cout<<"\nYour average is "<<average<<"\n""You are VERY GOOD and your status is CEMERLANG\n\n ";
else
cout<<"\nYour average is "<<average<<"\n""You are BRILLIANT and your status is TERBILANG\n\n";


break;

case '3':
break;


default:
cout<<"invalid operation";
break;
}

} while(operand !='3'); //the problems occur here and i cannot make it
quit the program
cout<<"End of Program!"<<endl;
}
return 0;
}
Hi,

Try this:


1
2
3
4
5
6
7
8
9
10
11
12
bool Quit = false;

while (!Quit) {
 switch // ..
  // ...
  case '3':
  Quit = true;
break;

//....

}
Hello amyblackpearl,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.


You have a couple of problems:

1. The program did not compile for me. If it did for you I would say that your compiler settings need changes or the compiler is old letting things happen that should not.

2. You should ALWAYS initialize your variables. When I trie to compile the program the error message listed uninitialized variables.

3. "choose" and "operand" should be defined as "int"s not "char"s. And "operand" is not even used.

4. Around line 83 the while condition of the do/while loop uses the variable "operand", but this variable is never changed in the program. With the variable uninitialized it will have an unknown value, on my computer an "int" variable is likely to have the value of -858993460, so when you reach the do/while condition this is "!= '3'".

5. When I changed "operand" to "choose" the program worked.

Some of the problems I had that you did not may be due to your compiler or compiler settings not catching what should be errors.

Hope that helps,

Andy
Hello amyblackpearl,

A minor problem I found is that "mark1" and "mark2" are defined as doubles, but "average" is defined as an int. When doing your calculations with doubles the result is a floating point number and then storing the result in an int you will keep the whole number, but loose the decimal portion.

This may work better defining "average" as a double.

If you include the header file "iomanip" you can use this std::cout << std::fixed << std::showpoint << std::setprecision(2); to limit the number of decimal place that are displayed. Change the two in std::setprecision(2) to the number of decimal places that yu want.

It slipped by me because I commented out the {}s before the "do" and before the "return" these {}s are not need.

Hope that helps.

Andy
omaigod thank you so mucccch andy no wonder i got a lot of warningsssssssss

i can perfectly make it run
Hello amyblackpearl,

You are welcome. I hope I have helped you understand something new.

Andy

P.S. When you are satisfied and done be sure to green check the post to let everyone you are finished.
Topic archived. No new replies allowed.