You should write a program that prompts the user for three floating point numbers of type double (using cout to prompt the user and write to the screen, or standard output stream, and cin to read in from the keyboard, or standard input stream). Name the variables nu through n3.
Next, the program should find the sum of n1 and n3 and store it in a variable named sum. The program should find the difference between n2 and n3 and store it in a variable called diff. The output should look exactly like this (don’t worry if there are extra zeroes at the end of the output of the answers):
Please enter number 1: 4.58
Please enter number 2: 3.3
Please enter number 3: 6.12
The sum is: 10.7
The difference is: -2.82
Be sure to declare five double variables, one for each of the input values, one for the sum, and one for the difference. The program should be fairly short, with five declarations, five output statements, three input statements, and one return statement inside of main() (not necessarily in that order).
/* Author Zachary Pennace
Date : Sepmtember 15th
Profesor Stuetzle
*/
Also, check your spelling, you have a few errors there, which won't matter a lot, but will be the extra half mark that could get you an A+ instead of an A.
Compiler/Debug Output
main.cpp: In function ‘int main()’:
main.cpp:28:37: error: ‘end1’ was not declared in this scope
std::cout << "please enter num1" << end1; // enter num1
^
The input of the test case:
5.5
1.8
8.8
Your code's output:
timeout: failed to run command ‘./a.out’: No such file or directory
The correct output of the test case:
Please enter number 1: Please enter number 2: Please enter number 3:
The sum is: 14.3
The difference is: -7
`diff` of correct output and your output:
*** skybox22032-SUID-1505d09f-cf34-4401-bf6c-50811d560dda/OUTPUT 2015-09-16 00:49:19.542434021 +0000
--- skybox22032-SUID-1505d09f-cf34-4401-bf6c-50811d560dda/EOUT 2015-09-16 00:49:19.398435819 +0000
***************
*** 1 ****
! timeout: failed to run command ‘./a.out’: No such file or directory
--- 1,3 ----
! Please enter number 1: Please enter number 2: Please enter number 3:
! The sum is: 14.3
! The difference is: -7
\ No newline at end of file
1) Check for all closing brackets, braces, and parentheses. You forgot to close out your iostream. And as @Radar mentioned, and #include namespace isn't actually a thing.
2) You have a few misspellings that would really kill your programs. It's not end1 as in, end + the number 1. It's endl, as in end + the lowercase of the letter L. I ran it through the online compiler cpp.sh, and after fixing those, it worked fine.
Highly doubt it. Also looking back at your code and your professor's instructions, I'm thinking he wants you to just declare variables and have keyboard input in order to assign values to them. His example of 4.58 and the other numbers was just an example. What your program is supposed to do is it's supposed to take any range of floats or doubles, I'm not sure, and give out the sum and difference of whatever you're supposed to manipulate.