Hi, I just have a question for anyone who can help. I am trying to write a program that will print to a file. The program has a while loop so that when I run it, it should print to the file each time the loop cylces. It is only printing the 2nd to last cycle, which makes no sense to me. Everything else seem in order, here is my loop.
I'm sorry I know I'm supposed to put it in some special format to post here, but I dont know how to do that. Thanks for any help! -
while(ID<999)
-
-
{
-
printf("\n\nEnter 3 digit student ID or 999 to end input: ");
-
-
scanf("%d",&ID);
-
if (ID==999)
-
break;
-
printf("Enter Quiz 1 Score (out of 10): ");
-
-
scanf("%d", &quiz1);
-
-
printf("Enter Quiz 2 Score (out of 10): ");
-
-
scanf("%d",&quiz2);
-
-
printf("Enter Quiz 3 Score (out of 10): ");
-
-
scanf("%d", &quiz3);
-
-
printf("Enter Test 1 Score (out of 20): ");
-
-
scanf("%d",&test1);
-
-
printf("Enter Test 2 Score (out of 20): ");
-
-
scanf("%d",&test2);
-
-
printf("Enter Final Score (out of 30): ");
-
-
scanf("%d", &final);
-
-
-
-
total = quiz1+quiz2+quiz3+test1+test2+final;
-
-
quiz = quiz1 + quiz2 + quiz3;
-
-
test = test1 + test2;
-
-
student=fopen(FILENAME, "w");
-
fprintf(student,"STUENT QUIZ MID_TERM FINAL GRADE\n");
-
-
if (total<55 && total>0)
-
-
t=0;
-
else
-
t= ((total-1)/10);
-
switch(t)
-
{
-
case 10: case 9:
-
{
-
printf("%d %5d %5d %5d \t A",ID, quiz, test, final);
-
fprintf(student,"%d %5d %5d %5d \t A\n",ID, quiz, test, final);
-
}
-
break;
-
-
case 8:
-
{
-
printf("%d %5d %5d %5d \t B",ID, quiz, test, final);
-
fprintf(student,"%d %5d %5d %5d \t B\n",ID, quiz, test, final);
-
}
-
break;
-
-
case 7: case 6: case 5:
-
{
-
printf("%d %5d %5d %5d \t C",ID, quiz, test, final);
-
fprintf(student,"%d %5d %5d %5d \t C\n",ID, quiz, test, final);
-
}
-
break;
-
-
case 0:
-
{
-
printf("%d %5d %5d %5d \t F\n",ID, quiz, test, final);
-
fprintf(student,"%d %5d %5d %5d \t F\n",ID, quiz, test, final);
-
}
-
break;
-
-
default:
-
printf("You have entered invalid information, please try again.");
-
-
-
}
-
fclose(student);
5 1633
What type is t? It appears as though you expect it to be an integer of value between 10 and five.
chevon1920-
I would make sure it is entering the loop (right in front of the while, set id so that it will definitely enter the loop) which will make sure the loop itself is only printing twice.
I'm pretty rusty on my C, but did you try flushing stdin?
What type is t? It appears as though you expect it to be an integer of value between 10 and five.
thanks for the reply,
I defined everything as an integer. And yes it should be between 10 and 5.
chevon1920-
I would make sure it is entering the loop (right in front of the while, set id so that it will definitely enter the loop) which will make sure the loop itself is only printing twice.
I'm pretty rusty on my C, but did you try flushing stdin?
I didnt think I needed an initial value for ID. Do you always need one, Its not going to a certain value, I was trying to set up and infinite loop. LOL, I have no clue what flushing stdin means, but Ill figure it and try it, thanks.
I didnt think I needed an initial value for ID. Do you always need one, Its not going to a certain value, I was trying to set up and infinite loop. LOL, I have no clue what flushing stdin means, but Ill figure it and try it, thanks.
Infinite loops, in general, are bad, but you can set them up very easily. In this case I'm sure you know that they are in the following format:
while ( condition )
{
do something
}
So all you really want is for condition to register as "true". In C and C++, this is pretty funny, it can be either a conditional statement (as you have a comparison, if ID is less than 999), or it can be a boolean - true or false. The funny thing about values and how they are read in conditional expressions is that 0 is false and any other number is true. This means an infinite loop is as easy as
while (1)
Simple, true, and will execute until your scanf() statement is read and breaks out from it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Poster |
last post by:
I have a script, its outputs are in HTML. It displays perferctly in a
browser, however when I view source, it gives me the JS scripts, but I want
to view the HTML output. Is there a way I can view...
|
by: Mark C |
last post by:
All,
I have exhaustingly been looking through the newsgroups in search of a way
to systemically output an Access 97 report to a pdf file using the full
version of Adobe Acrobat. I want the user...
|
by: Xh |
last post by:
Hi All,
I have problems with generating valid HTML output
there are few HTML elements that i don't what to output as <tagname/>
but as <tagname></tagnamebut Xalan keeps generating them as...
|
by: Linda Liu[MSFT] |
last post by:
Hi Al,
Based on my understanding, you have an application which prints something
to printers. The problem is that the font of "OCR A Extended" cannot be
printed properly on some of printers. If...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |