Computer problems,Computer help
*AX SOFT>>>Programming & Design

Can some one help me to check why cant my program work. thanks?


#include <stdio.h>
int main(void)
{
double TotalScore = 0,
GPA = 0;
int NoOfSubjects;
int i = 0;
char Grade;

printf( "Enter the number of subjects: " );
scanf( "%d", &NoOfSubjects );

do
{
printf( "Enter the grade ( A, A-, B+, B, B-, C+, C, D, F ): \n" );
scanf( "%c",&Grade );
getchar();

if( Grade == 'A' || Grade == 'a' )
TotalScore = TotalScore + 4.00;
else if ( Grade == 'A-' || Grade == 'a-' )
TotalScore = TotalScore + 3.70;
else if ( Grade == 'B+' || Grade == 'b+')
TotalScore = TotalScore + 3.30;
else if ( Grade == 'B' || Grade == 'b' )
TotalScore = TotalScore + 3.00;
else if ( Grade == 'B-' || Grade == 'b-' )
TotalScore = TotalScore + 2.70;
else if ( Grade == 'C+' || Grade == 'c+' )
TotalScore = TotalScore + 2.30;
else if ( Grade == 'C' || Grade == 'c' )
TotalScore = TotalScore + 2.00;
else if ( Grade == 'D' || Grade == 'd' )
TotalScore = TotalScore + 1.00;
else
printf( "invalid grade\n" );
}
while ( i <= NoOfSubjects, i++ );

Firstly.... You should follow some conventions...

#include <stdio.h>
Should be
#include <cstdio>

And all of these
TotalScore = TotalScore + 4.00;
Should be
TotalScore += 4.00;

It's nicer.



getchar();

^ You're not doing anything with this. Try

Grade = getchar();

:)

Few problems easily identifiable:
1) TotalScore has a COMMA after the command line instead of a semi-colon.
2) Cast a type to GPA, I recommend Double
3) Put a space between the cast and your increment variable "i"
4) Your scanf to get the grade is going to lob off any values after the first character (ie: + / -). "Grade" should be cast as an array of char, captured using %s instead of %c if using scanf.
5) Your incrementer is doing a post inc, meaning if your number of subjects is "1", it will run the loop twice (once for 0 and once for 1).
6) The function is not complete. There is no output, and it's missing the closing brace for the main function.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • What type of website is this?

    It's a directory.

    ...
  • In C++ Convert each decimal number to the nearest integer??

    Your logical operators are taking affect.. putting the "+" in presidence before the function base it's self... so it's adding together the floating point values of a-e, then set...

  • What form input type does this?

    checkboxes? radio buttons, you can only select 1 in a group pull down menus can only select 1 listboxes in VB you can select more than 1 what language would this be in? I initially thought...

  • How make your own website??

    WHAT YOU NEED; 1.Domain name & Hosting (to display site) needed. Buy it... ...

  • Can somebody tell me what the error is in this PHP line?

    looks like your missing a "," after the ssn: (line 13) if(isset($_REQUEST['agree'], $_REQUEST['firstname'], $_REQUEST['lastname'], $_REQUEST['address...

  • Photoshop. Need help on technique. Example inside.?

    Open any image you need with photoshop, zoom it at size you can edit it, use earser tool to remove the background, finally, duplicate the layer to another new one and change blending options to add...

  • How to make brighter, detailed photos in photoshop for website?

    curves, levels, and better images to begin with... at least more res maybe? the noise you're getting is because the images are too dark/ overexposed.

    ...
  • What is the linux command line for displaying a website?

    The original text-based browser was Lynx. If that's what you mean. I don't know how Gentoo installs software, but downloading (or checking for if it IS installed) is the first step. Then,...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster