-
February 21st, 2011, 04:19 AM
#1
C++ code: Unable to construct "char" and "if else" statement
Hello:
I have written code for the following problem but, unable to get the correct results, please advise me as to how to fix it.
I also, tried using char for making a declaration and in the statements. But,I removed it because it had too many errors. What is the correct way to format char for this type of problem.
Thank You in advance.
Question
Jack is organizing a boat trip and needs to decide how many boats to order to hold all the people attending the event.
Write a complete C++ program that
1.prompts the user for the number of people that plan to attend the event.
2. prompts him for how many people will fit in a boat. (Assume each boat will hold the same number of people).
3. It then prints outs a message telling him how many boats he will need and whether they will be full or not.
SAMPLE RUN:
How many people are going?: 137
How many people will fit in a boat: 10
You will need 14 boats for 137 people.
13 of them will be full and one will have only 7 people.
ANOTHER SAMPLE RUN:
How many people are going?: 144
How many people will fit in a boat: 12
You will need 12 boats for 144 people.
All of them will be full.
MY CODE
#include <iostream>
using namespace std;
int main()
{
int Total_of_People_Attend_Event;
int How_Many_Boats;
int People_Per_Boat=Total_of_People_Attend_Event/How_Many_Boats;
cout << "What is the Total_of_People_Attend_Event:\n";
cin >> Total_of_People_Attend_Event;
cout << "How_Many_Boats:\n";
cout << "How many people:" << People_Per_Boat <<'\n';
if (How_Many_Boats = 14)
{
cout << "need_14_boats_are_not_full:\n";
}
else
cout << "You_need_12_boats_which_are_full:\n";
return 0;
}
-
February 21st, 2011, 06:04 AM
#2
Re: C++ code: Unable to construct "char" and "if else" statement
There are quite a number of basic errors in those few lines of code.
I would highly recommend you to grab a C++ book and read it.
-
February 21st, 2011, 06:05 AM
#3
Re: C++ code: Unable to construct "char" and "if else" statement
Some issues with the code:
- You cannot use Total_of_People_Attend_Event and How_Many_Boats to calculate People_Per_Boat before you have assigned values to them.
- After writing "How_Many_Boats", you should use cin again to read the value from the user.
- Comparing in C++ uses operator == and not operator =
- You are hardcoding values 14 and 12, that's not what your assignment is asking for.
-
February 21st, 2011, 07:32 AM
#4
Re: C++ code: Unable to construct "char" and "if else" statement
Thank you for the help and if you know of a good Tutorial or textbook link for C++ beginners please let me know. I've tried several but, some of the information was outdated. I'm now using the Problem Solving with C++ by Walter Savitch.
Have a Nice Day!
-
February 21st, 2011, 07:34 AM
#5
Re: C++ code: Unable to construct "char" and "if else" statement
Take a look at this list of books.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|