Hey. I am VERY new to C++. Here is what I need to program in C++. I am using Dev CPP tool.
Create a C++ application that will ask the user for the number of watermelons. The application will output how many slices are available. There are 8 slices per watermelon. If the user inputs 2 watermelons the output should be 16 slices.
Here is what I have gotten so far.....
#include <iostream>
using namespace std;
int main()
{
int num_of_watermelons, slices_of_watermelon;
cout << "Press return after entering a number. \n";
cout << "Enter the number of watermelons:\n";
cin >> number_of_watermelons;
cout << "Enter the number of watermelons:\n";
cin >> number_of_watermelons;
slices_of_watermelon = number_of_watermelons * 8;
cout << "If you have ";
cout << "number_of_watermelons;
cout << "You have ";
cout << "number_of_slices";
return 0;
}
Can someone please tell me what I am doing wrong? Again, I am very new to C++ but I am trying. Please help!
#include <iostream>
usingnamespace std;
int main()
{
int num_of_watermelons, slices_of_watermelon;
cout << "Press return after entering a number. \n";
cout << "Enter the number of watermelons: ";
cin >> number_of_watermelons; //<<----------------------dosn't match your declareation num_of_watermelons
slices_of_watermelon = number_of_watermelons * 8; //<<---dosn't match your declaration num_of_watermelons
cout << "If you have ";
cout << "number_of_watermelons; //<<---------------------you have an extra " here, variable name is wrong should be num_of_watermelons
cout << " You have ";
cout << "number_of_slices"; //<<------------------------don't wan't " here, wrong name should be slices_of_watermelon
return 0;
}
The program is now loading, but when I run the program and it asks me to enter the number of watermelons and I enter the number and press enter, it instantly exits the program. How I do I correct this?