I just started programming and I am already stuck on my first assignment. :( The professor told us to code the following and finds any errors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
usingnamespace std ;
int main ()
{
int BREAD = 63; //calories in a slice of bread
int CHEESE = 106; //calories in a slice of cheese
int MAYONNAISE = 49; //calories in 1 gram of mayonnaise
int PICKLE = 25; //calories in a slice of pickle
int TotalCalories = BREAD + CHEESE + MAYONNAISE + PICKLE;
cout << "There were" << TotalCalories <<
cout << "calories in my lunch yesterday." << endl;
cout << "What is for lunch today?" << endl;
return 0;
}
There are 2 slices of bread, 3 slices of cheese, 4 pieces of pickles, and 2 grams of mayonnaise. I think I will have to put something like
BREAD = 63 * 2;
And then add them together, correct? But when I tested the initial code, I get this weird number 2436......C3E8. I tried to make it show the right answer, but I haven't been able to figure it out. Also, were there any syntax or coding errors?
std::cout << std::cout does print something
(an address, which would look something like what you got: 0x2436C3E8).
See the difference between the two lines printed out in this program:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
int main()
{
int i = 123456789 ;
// print an address, an integer, an address, a new line
std::cout << std::cout << i << std::cout << '\n' ;
// print an integer, and then then a new line
std::cout << i << '\n' ;
}