Can some 1 debug this for me and help me print the output

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-22-2008
clezzie
Can some 1 debug this for me and help me print the output
Ok so heres the deal. I need the program to print in two columns, one with the number of quizzes two wit the grade from each quiz, and then at the end i need the average to print, here is the code so far

Code:

```int main() {         //Define Varibles int and floats         int gone,gtwo,gthree,gfour,gfive,gsix,gseven,geight,gnine,gten,k,avg,sum;                                 //User Input         printf("Please enter the 10 grades, make sure you space and use commas to differentiate each grade");         scanf("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i",&gone,&gtwo,&gthree,&gfour,&gfive,&gsix,&gseven,&geight,&gnine,&gten);                                 //Check Input         if (gone == -gone||gtwo == -1||gthree == -gthree||gfour == -gfour||gfive == -gfive||gsix == -gsix||gseven == -gseven||geight == -geight||gnine == -gnine||gten == -gten)                         printf("Please enter a positive grade. Grades can not be negative");                         else         {                 sum = gone+gtwo+gthree+gfour+gfive+gsix+gseven+geight+gnine+gten;                                 avg = sum/10;         {                                         while(k <=10)                 {                         k++;                         printf("%i,%i",k,avg);                                         }         return 0;         }```
• 10-22-2008
tabstop
1. gone==-gone does not check to see if gone is negative, it checks (in a very roundabout way) to see if gone is zero.
2. If you intend to use a for loop to print your quiz scores, your quiz scores must be in an array.
• 10-22-2008
clezzie
i dont think my prof wants arrays but i think it would be best if i use it also im tryin 2 say if the number enter is negative then dont do the else...is there a general way i can say that??
• 10-22-2008
tabstop
If your prof didn't want arrays, he wouldn't have given the assignment.

That's what if means -- do either or the other, but not both. So put everything you don't want done in the negative case in the else clause of your if-statement.
• 10-22-2008
clezzie
makes total sense now thanks,im going 2 rewrite n get bck 2 u
• 10-22-2008
Salem
> # gone==-gone does not check to see if gone is negative, it checks (in a very roundabout way) to see if gone is zero.
Unless you happen to be using a 1's complement machine, in which case it means something else ;)
• 10-22-2008
tabstop
It's not ~, it's -. I fail to see how using a one's complement machine will change the rules of mathematics.
• 10-22-2008
laserlight
Quote:

Originally Posted by tabstop
I fail to see how using a one's complement machine will change the rules of mathematics.

Possibly because there are two representations for zero in one's complement arithmetic, hence +0 != -0. Then again, I have never had the chance to actually use an implementation that uses one's complement.
• 10-22-2008
Salem
+0 and -0 have separate representations, so I don't see how they would compare equal.
• 10-22-2008
laserlight
Oh, better yet, in section 6.2.6.2, C99 says that "it is unspecified whether these cases actually generate a negative zero or a normal zero, and whether a negative zero becomes a normal zero when stored in an object." Here, "these cases" refer to the use of certain operators like unary + and unary - which may generate a negative zero if the implementation supports negative zeros.

Consequently, whether +0 != -0 in one's complement in a C program is implementation defined.
• 10-22-2008
tabstop
I apologize; I thought the standard required positive zero and negative zero to compare equal, but I see now that it only permits it.
• 10-22-2008
clezzie
ok im having problems again this is wut the hw says: Design a program in C which will compute the total grade as well as the average grade received by a student for 10 quizzes. Each quiz grade is out of 10 points. When the program is executed, the user will be asked to input the 10 grades in succession. The output is in the form of a tabular display on the monitor which consists of two columns, one for Quiz # and the other for Quiz Grade. The total and average grade values are to be printed below the table.

where the hell do i put the arrays if its coming as a user input
• 10-22-2008
clezzie
heres the new code

Code:

```int main() {         //Define Varibles int and floats         int gone,gtwo,gthree,gfour,gfive,gsix,gseven,geight,gnine,gten,counter,avg,sum;                                 //User Input         printf("Please enter the 10 grades, make sure you space and use commas to differentiate each grade  ");         scanf("&#37;i,%i,%i,%i,%i,%i,%i,%i,%i,%i",&gone,&gtwo,&gthree,&gfour,&gfive,&gsix,&gseven,&geight,&gnine,&gten);                                 //Check Input         if (gone >= 0||gtwo >= 0||gthree >= 0||gfour >= 0||gfive >= 0||gsix >= 0||gseven >= 0||geight >= 0||gnine >= 0||gten >=0)         {                 sum = gone+gtwo+gthree+gfour+gfive+gsix+gseven+geight+gnine+gten;                 avg = sum/10;                                         for(counter=1; counter <=10; counter++)                         {                         counter = counter;                         printf("%i\t%i\n",counter,gone,gtwo,gthree,gfour,gfive,gsix,gseven,geight,gnine,gten);                         }         }         else         {                 printf("Please enter a positive grade. Grades can not be negative");                         }                 printf("%i\t%i\t%i",counter,avg,sum);                 getch();                 return 0; }```

but i need my program to loop and the output to look like this
1 80
2 82
3 50
4 90
5 78
6 90
7 100
8 35
9 11
10 65
• 10-23-2008
clezzie
can any 1 help me wit my output??
• 10-23-2008
matsp
Code:

```int *ptrArr[] = { &gone,&gtwo,&gthree,&gfour,&gfive,&gsix,&gseven,&geight,&gnine,&gten }; int i; ... for(i = 0; i < sizeof(ptrArr)/sizeof(ptrArr[0]); i++) {   printf("%d\t\%d\n", i, *ptrArr[i]); }```
There, problem solved.

[Of course, your professor will know immediately that you didn't come up with this yourself, at least if he asks you to explain what the code does, so you are probably better off working out how to solve it yourself].

--
Mats

--
Mats
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last