424,948 Members | 663 Online
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

# Whats wrong with this why does it not add all the numbers together and display them

OK for future questions you should include more text in the post explaining the problem and the title should be a summary. I am aware that the "Ask a Question" page does not make this clear.

You problem is line 38 of your listing
add >> number1 + number2 + number3 + number4 + number5;
This is a valid numerical expression so it compiles (return the value of add shifted right by the sum of all the number variables).

You need to use the assignment operator (=) to assign the sum of all the number variables to add.

10 Replies

 Expert Mod 5K+ P: 8,916 OK for future questions you should include more text in the post explaining the problem and the title should be a summary. I am aware that the "Ask a Question" page does not make this clear. You problem is line 38 of your listing add >> number1 + number2 + number3 + number4 + number5;This is a valid numerical expression so it compiles (return the value of add shifted right by the sum of all the number variables). You need to use the assignment operator (=) to assign the sum of all the number variables to add. Sep 22 '10 #2

 Expert 100+ P: 2,396 By the way, what do you expect lines 17-21 to do? These lines assign the result of a logical expression to those variables. Logical expressions can only have the values 0 or 1. Sep 22 '10 #3

 P: 8 yes i figured that all out thank you and as for the rest of the program I need to assign a letter grade to the outcome of the average grade. I made necessary changes by adding const int of A = 1 B=2 C=3 D=4 F=5 the other ints have been removed and I need to place the variable of A=90+ B=80>90 C=70>80 D=60>70 and F=>60 where would this go and I am not sure of the formula to insert it. Should it be with a if statement or something else? Thanks for you help Sep 22 '10 #4

 Expert 100+ P: 983 Well, a series of ifs can do it for you. Something like this? Expand|Select|Wrap|Line Numbers if (add >= 90) grade = A; else if (add >= 80) grade = B; ... etc ... Sep 22 '10 #6

 P: 8 this is not working right it keeps saying need to have ; and else if does not match the if Expand|Select|Wrap|Line Numbers //Display average cout << "Total grade average is /n:" << (number1 + number2 + number3 + number4 + number5) / 5; average;       if (average >= 90) grade = A;{       cout << "A /n";       cout << "GREAT JOB!!! /n";       }       else (average >= 80) grade = B;{       cout << "B /n";       cout << "NICE WORK!!! /n";       }       else if (average >= 70) grade = C;{       cout << "C /n";       cout << "Good Work! /n";       }       else if (average >= 60) grade = D;{       cout << "D /n";       cout << "WORK HARDER YOU CAN DO IT! /n";       {       else if (average < 60) grade = F;{       cout << "F /n";       cout << "YOU NEED TO WORK EVEN HARDER!!! /n";       } system("pause"); return 0; } Sep 22 '10 #7

 P: 1 my problem is that cout is an object ,how it is defined .it is an object of class ostream. Sep 22 '10 #8

 P: 1 // Add all 5 numbers together (Don't need to to this) (number1 + number2 + number3 + number4 + number5); Sep 22 '10 #9

 Expert Mod 5K+ P: 8,916 On line 7 in code of post 7 you are missing an if. I expect the compiler was producing an error at line 11. When you get compiler errors if the error is not immediately obvious on the line the compiler has highlighted then you need to learn to look back and the previous few lines of code. Sep 22 '10 #10

 Expert 100+ P: 983 Goodness, this is a little confused. Yes, Banfa is right, you are missing an "if" on line 7. Before that, though, line 3 (as well as 7 and others) is apparently malformed. Did you mean to write something like: Expand|Select|Wrap|Line Numbers       if (average >= 90) { grade = A;  Where the opening brace started the consequent of the "if", and not an independent "block statement" following the "if"? Good luck! Sep 22 '10 #11