Guys can you Help me make my program into a Loop.. please :)

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
char name[40];
float exam,q1,q2,q3,ass,sw,att,cs,term,ave;")
printf("Name:\t");
gets(name);
printf("\nExam:\t");
scanf("%f",exam);
printf("\nQuiz#1:\t\t");
scanf("%f",q1);
printf("\nQuiz#2:\t\t");
scanf("%f",q2);
printf("\nQuiz#3:\t\t");
scanf("%f",q3);
printf("\nAssignment:\t");
scanf("%f",ass);
printf("\nSeatwork:\t");
scanf("%f",sw);
printf("\nAttendance:\t");
scanf("%f",att);
ave=(q1+q2+q3)\3
cs=((ass*.4)+(sw*.4)+(att*.2))*.3
term= exam*.4+ ave*.3+cs
printf("\nTerm Grade:\t%2.2f",term);
printf("\nRemark:\t");
if(term >=90)
printf("Excellent!");
else if(term >=80)
printf("Satisfactory");
else if(term >=76)
printf("Good");
else if(term == 75)
printf("Passing");
else if(term <75)
printf("Failed");
getch();
}
can quite grasp how to turn it into a loop no matter how i read the instruction.. >_< can you guys teach me.. :) the output of my program looks like this..

This is the output:

Name:
Exam:
Quiz#1:
Quiz#2:
Assignment:
Seatwork:
Attendance:
Term Grade:
Remark:


How can i turn it into this:




Name:
Exam:
Quiz#1:
Quiz#2:
Assignment:
Seatwork:
Attendance:
Term Grade:
Remark:
Try Again [Y/N]:
Thank you for using my program...



~~~ Looping this program that if you press "Y" at the end it will clrscr and then start at the name again and if you press the "N" then it will only display.. "Thank you for using my program..." at the end..

any kind of guide would help me alot in understanding how it works.. :) thank you very much in advance!!!
Last edited on
Have a char variable say:

 
char again = 'Y';


and then have a while condition:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
   char again = 'Y';

   while (again == 'Y' || again == 'y')
   {
      // your code
      // ...
      cin >> again;
   }

   return 0;
}
Thanks Man!!! I kinda got it now :) ill try make the program now :)
Or ...

1
2
3
4
5
...
   do
   {

   } while (again == 'Y' || again == 'y');
Guys correct me if im wrong im kinda new on Turbo C.. dont have turbo c on may laptop cos it cant run on windows 8 -___-"... and btw guys if "again" is how you continue the loop what is the counter part? so i will put it on the "N" to display "Thank you for using my program..."




#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
char again = 'Y';
while (again == 'Y' || again == 'y')
{
char name[40];
float exam,q1,q2,q3,ass,sw,att,cs,term,ave;")
printf("Name:\t");
gets(name);
printf("\nExam:\t");
scanf("%f",exam);
printf("\nQuiz#1:\t\t");
scanf("%f",q1);
printf("\nQuiz#2:\t\t");
scanf("%f",q2);
printf("\nQuiz#3:\t\t");
scanf("%f",q3);
printf("\nAssignment:\t");
scanf("%f",ass);
printf("\nSeatwork:\t");
scanf("%f",sw);
printf("\nAttendance:\t");
scanf("%f",att);
ave=(q1+q2+q3)\3
cs=((ass*.4)+(sw*.4)+(att*.2))*.3
term= exam*.4+ ave*.3+cs
printf("\nTerm Grade:\t%2.2f",term);
printf("\nRemark:\t");
if(term >=90)
printf("Excellent!");
else if(term >=80)
printf("Satisfactory");
else if(term >=76)
printf("Good");
else if(term == 75)
printf("Passing");
else if(term <75)
printf("Failed");
cin >> again;
}
getch();
return0;
}
Last edited on
Your initial question asked how to continually loop while the user typed 'Y' or 'y' to the question "Try Again [Y/N]". So I provided the answer for your user input (a char) into a variable that the program checks to decide whether to loop again or not. So it will loop while the variable contains either the character 'Y' or 'y'. There's no counter, as it isn't a for(...) loop, its either a while or do | while loop.
so if i use the "do" will it look like this?

int main
{
char again = 'Y';
do
{
printf("\nThank You For Using This Program...");
}while(again == 'Y' || again == 'y');


Topic archived. No new replies allowed.