- Joined
- Sep 5, 2007
- Messages
- 512 (0.08/day)
System Name | HAL_9017 |
---|---|
Processor | Intel i9 10850k |
Motherboard | Asus Prime z490-A |
Cooling | Corsair H115i |
Memory | GSkill 32GB DDR4-3000 Trident-Z RGB |
Video Card(s) | NVIDIA 1080GTX FE w/ EVGA Hybrid Water Cooler |
Storage | Samsung EVO 960 M.2 SSD 500Gb |
Display(s) | Asus XG279 |
Case | In Win 805i |
Audio Device(s) | EVGA NuAudio |
Power Supply | CORSAIR RM750 |
Mouse | Logitech Master 2s |
Keyboard | Keychron K4 |
Well, the title is simple. I have an intro C++ assignment that for some reason, will not work. I am just not sure why it isn't.
Here is a background:
I have to build a program (win32) to show a list of people attending a conference. Here is the price:
1-3: 150.00 per person
4-9: 100.00 per person
10+: 90.00 per person
Now, i need the user to keep inputing people (from different companies) untill they tell it to stop. (I am required to use a while loop).
The program is suppost to calculate the total number of people entered, and display the average cost per person.
What I keep getting is the number of people to equal -1, and cost of 0. I'm about to stop my foot and swear some more, but not sure how that would help.
If anyone can give me any tips on how to get this to work. I would be most grateful.
Just as a note. I'm not asking you do it for me, I wont learn anything that way. I want to understand the whos and why, otherwise I'd just be a cheating P.O.S.
Thanks alot TPU,
-Andrew
I have to do this in Visual Studio C++ Express 2005.
And here is my code so far:
Here is a background:
I have to build a program (win32) to show a list of people attending a conference. Here is the price:
1-3: 150.00 per person
4-9: 100.00 per person
10+: 90.00 per person
Now, i need the user to keep inputing people (from different companies) untill they tell it to stop. (I am required to use a while loop).
The program is suppost to calculate the total number of people entered, and display the average cost per person.
What I keep getting is the number of people to equal -1, and cost of 0. I'm about to stop my foot and swear some more, but not sure how that would help.
If anyone can give me any tips on how to get this to work. I would be most grateful.
Just as a note. I'm not asking you do it for me, I wont learn anything that way. I want to understand the whos and why, otherwise I'd just be a cheating P.O.S.
Thanks alot TPU,
-Andrew
I have to do this in Visual Studio C++ Express 2005.
And here is my code so far:
Code said://Lab 2 - ITCS 1214
//Created and revised by Atnevon
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;
int main()
{
//declare variables
int registrants = 0;
double price = 0.0;
double charge = 0.0;
double cost = 0.0;
//find how many people are attending
cout << "How many company registrants will be attending? (Enter -1 to stop): ";
cin >> registrants;
while (registrants >= 0)
{
//make sure at least one person attends
charge = registrants * price;
registrants = registrants + 1;
//get remaining temperatures
cout << "...and in addition to that company?: ";
cin >> registrants;
} //end while
//make if/else for price ranges
if (registrants >=1 && registrants <= 3)
price = (registrants * 150.00);
else if (registrants >=4 && registrants <= 9)
price = (registrants * 100.00);
else if (registrants >=10)
price = (registrants * 90.00);
{
//calculate and display the average price per person
total = registrants * price;
charge = cost / registrants;
cout << "Total Registrants: " << registrants << endl;
cout << "Average Price: " << charge << endl;
}
return 0;
} //end of main function