My current code isn’t running properly in MS Visual Studio? - c++

I am working on a project for the office today and I’m running into a bit of a stumble today on it. My code is properly debugged but it when ran it ignores all the parameters I set up and becomes smashed all together in a one line executable (if that makes sense). Here’s the prompt and what I have so far:
“A business needs to calculate the bonus points for sales representatives. The bonus points are based on how much each sales representative sold the year.
Write a program to prompt the user to enter the sales amount for a sales representative. Include different functions for each group of Sales representatives.
Display the bonus points as integers.
Please see the table showing the Groups, Sales, and Bonus points:
Groups Sales Bonus points:
A $0 - $100, 000 500 points
$100, 001 - $1,000,000 1, 500 points
B $1,000,001 - $2,000, 000 2,000 points
$2,000,001 - $3,000, 000 2, 500 points
C $3,000,001 - $4,000, 000 3, 000 points
$4,000,001 and over 5, 000 points
Input Validation: Do not accept negative numbers for sales.”
And here’s what I have tried so far:
#include <iostream>
#include <iomanip>
using namespace std;
float salesamounts; //sales made
int username; // Sales rep name
int main()
{
cout << “Please enter your sales made for the year: $”
cin >> salesamounts;
cout << endl;
// exception on program
if (salesamounts <= -1);
{
if (salesamounts <= -1);
cout << “Value cannot be negative. Please input again.”
}
// Group A placement
for (;salesamount <= 100000;)
{
if ((salesamounts <= 100000)
cout << “Congratulations! You earned 500 Bonus Points!”
break;
{
for (; salesamounts > 100001 < 1000000;)
{
if ((salesamounts > 100001 < 1000000));
cout << “Congrats! 10000 Bonus Points have been credited to you!”
break;
}

According to your requirement, you could use if-elseif-else to judge each group of Sales representatives, which is like:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double salesamounts; //sales made
int username; // Sales rep name
cout << "Please enter your sales made for the year : $" << endl;
while (cin >> salesamounts) {
// exception on program
if (salesamounts < 0.0) {
cout << "Value cannot be negative.Please input again." << endl;
}
//judge salesamounts
else if (salesamounts>0.0 && salesamounts <= 100000.0) {
cout << "Congratulations!You earned 500 Bonus Points!" << endl;
}
else if (salesamounts > 100000.0 && salesamounts <= 1000000.0) {
cout << "Congrats!1500 Bonus Points have been credited to you!" << endl;
}
else if (salesamounts > 1000000.0 && salesamounts <= 2000000.0) {
cout << "Congrats!2,000 Bonus Points have been credited to you!" << endl;
}
else if (salesamounts > 2000000.0 && salesamounts <= 3000000.0) {
cout << "Congrats!2,500 Bonus Points have been credited to you!" << endl;
}
else if (salesamounts > 3000000.0 && salesamounts <= 4000000.0) {
cout << "Congrats!3,000 Bonus Points have been credited to you!" << endl;
}
else if (salesamounts > 4000000.0 ) {
cout << "Congrats!5,000 Bonus Points have been credited to you!" << endl;
}
else {
break;
}
}
}
By the way, you could also use switch statement to do this.

You did the input part almost correctly, but after that you confused the if-else-if part with for loops.
When taking the user input, you can use a while loop to check whether the value is negative or not. This will make the program to prompt the user to enter a value again if the entered value does not match the criteria:
float salesamounts;
cout<<"Enter the sales amounts for the year:"; //the program will prompt the user initially
cin>>salesamounts; //user inputs the value here
while(salesamounts<0) //this line checks if the value is negative, if yes, it'll continue running this block till the value is non-negative
{
cout<<"Negative numbers not allowed. Please enter again: "; //Suppose the value is negative. Then the program will display this line and prompt the user to enter again
cin>>salesamounts; //user enters the value again
}
The next step in your program is to then check the user input and make the program act accordingly. The if-else statement will do that perfectly:
if (salesamount<=100000) //checks the value. If this is true, then then the following line will run. Else, the program will move to the next check.
cout<<"Bonus point is 500"; //displays the output if the above condition is correct
else if (salesamount<=1000000) //second check
cout<<"Bonus point is 1500"; //displays if the second condition is true
.
.
.
else
cout<<"Bonus point is 5000";
and so on.
Just to clarify, a loop is used only when you want a particular block of code to run repeatedly, whereas, to check or compare two values, you use the if-else statement.
Note that I've not written the second check as if (salesamounts>=100001 && salesamounts<=1000000) and also, I gave the last check as only else, not else if.

Related

Why is my do/while loop in c++ not allowing me to input 'amount' more than once?

I am attempting to develop a vending machine in C++ in which the user can insert as many 50 cent, 20 cent, and 10 cent coins as they would like to then move on to the 'purchase' of a product.
So far, my primitive code runs smoothly; the issue I am currently facing is that I can only 'insert' coins into the vending machine once, even though I think the 'while' condition in the 'do/while' statement is being executed.
Below you can find my code:
`
#include <iostream>
using namespace std;
int main() {
int productid;
string order, finished;
int amount;
cout << "Welcome to the coffee machine! We have a variety of beverages we can offer. \n Here is our selection: \n 1) Coffee- 50 cents \n 2) Tea- 60 cents \n 3) Cappuccino- 80 cents\n";
cout << "Please select your drink of choice by entering its ID: (1, 2, or 3)";
cin >> productid;
if (productid != 1 && productid != 2 && productid != 3){
cout << "That is an invalid entry; please try again. \n";
cin >> productid;
}
cout << "Please insert your coins. \n This vending machine only accepts 50 cent coins, 20 cent coins, and 10 cent coins. \n ";
cout << "When finished, please input '0'. ";
cin >> amount;
if (amount != 50 && amount != 20 && amount != 10 && amount != 0){
cout << "That is an invalid coin; please insert coins again.\n";
cin >> amount;
}
do {
amount += amount;
}
while (amount != 0);
return 0;
}
`
I was expecting to be able to insert coins until I input '0', but the code terminal says 'Process finished with exit code 0' after I insert coins once, thereby not allowing me to continue to insert coins.
If anyone has any suggestions as to how I could fix this so that the user can continuously insert coins until they input '0' I would greatly appreciate it.
Please feel free to leave any suggestions as to how to proceed as well.
Thank you
Your do-while looks like this:
do {
amount += amount;
}
while (amount != 0);
What does this do? It adds amount to itself until eventually it is 0. This can happen due to the fact that numbers are stored in a finite number of bits in memory and when due to some operation (value assignment in this case) is greater than the maximum value that can be stored for the given type, then the value will overflow its type limits and may get a smaller value than prior to the addition as a result, maybe even 0.
However, this is definitely not what you want.
You want: to read amount repeatedly until it's 0 and add it to a sum
You actually do: read amount exactly once, then add it to itself until it's 0
How to remedy this:
Move the reading inside the code and make sure that the sum will be a different variable:
cout << "Please insert your coins. \n This vending machine only accepts 50 cent coins, 20 cent coins, and 10 cent coins. \n ";
cout << "When finished, please input '0'. ";
int sum = 0;
do {
cin >> amount;
if (amount != 50 && amount != 20 && amount != 10 && amount != 0){
cout << "That is an invalid coin; please insert coins again.\n";
} else {
sum += amount;
}
}
while (amount != 0);
You need to put the do { ... } while(...); around the entire block you'd like to repeat. Also, you need a separate variable for the sum.
int amount, sum = 0;
// ...
cout << "Please insert your coins. \n This vending machine only accepts 50 cent coins, 20 cent coins, and 10 cent coins. \n ";
cout << "When finished, please input '0'. ";
do {
cin >> amount;
while (amount != 50 && amount != 20 && amount != 10 && amount != 0){
cout << "That is an invalid coin; please insert coins again.\n";
cin >> amount;
}
sum += amount;
}
while (amount != 0);
I've also changed an if to a while in your code for the case when the user makes multiple mistakes.
To solve these cases yourself, it's recommended that you either use a debugger and step through your code; or add some logging into the code an check what's going on (e.g., what the loop repeats).
the reason why the program does not ask you for another input is because the do-while loop only includes one line: amount += amount;
Also this is the issue why the program terminates, it gets stuck in this loop of adding amount on itself and when the int overflow happens and the amount gets zero value, the program terminates. You can check this behavior by printing out the amount variable in the loop.
amount += amount;
cout << amount << endl;
To fix the issue, you need to move couple of lines inside do block.
do {
cout << "Please insert your coins. \n This vending machine only accepts 50 cent coins, 20 cent coins, and 10 cent coins. \n ";
cout << "When finished, please input '0'. ";
cin >> amount;
cout << amount << endl;
if (amount != 50 && amount != 20 && amount != 10 && amount != 0){
cout << "That is an invalid coin; please insert coins again.\n";
cin >> amount;
}
amount += amount;
cout << amount << endl;
}
while (amount != 0);
Also, you need one more variable for the sum of coins (amount). This way if you add only one coin, the amount variable will be doubled.
Hope this helps.

How do I calculate and display the correct percentage?

I am a C++ noob.
I am trying to work on this text-based game for school, and I am having trouble with displaying the correct percentage. I think this has to do with how I calculate it in the program, or I am screwing something up with the function.
I would be most grateful for some assistance. Cheers.
#include <string>
#include <cmath>
#include <iostream>
using namespace std;
double menu (float crew_count);
double calculatePct(float crew_count, float number_of_deaths)
{
double percent = ((crew_count - number_of_deaths) / crew_count) * 100;
}
double welcome ()
{
int crew_count;
string backstory = "\nYou are in charge of a top-secret military mission, when your\nspace ship makes an emergency landing, on the largest moon of planet Gork.\nThe space ship is damaged. Oxygen levels begin to drop.\nHow many military personnel are on your ship?\nNumber of personnel: ";
cout << backstory;
cin >> crew_count;
if (crew_count >= 1)
menu(crew_count);
else if (crew_count < 1)
cout << "\nThere must be 1 or more members of the crew! Please enter a valid number!\n";
}
double menu (float crew_count)
{
double percent;
double main_option;
cout << "\nChoose one:\n1. Attempt repairs on the ship.\n2. Request an emergency rescue from mission command.\n3. Break protocol and reveal the top-secret space ship's location,\nto the Russians on a nearby moon, asking for their assistance.\nYour choice: ";
cin >> main_option;
if (main_option == 1)
{
cout << "\nToxic material on the moon has corroded the launch gear, and the \nlaunch exploded!\n\nThere were no survivors.\n";
}
else if (main_option == 2)
{
cout << "\nThe oxygen was depleted before the rescue team arrived.\nThere were 4 people killed.\n";
if (crew_count <=4)
cout << "0% of crew members were rescued!\n";
else
float percent = calculatePct(crew_count, 4);
cout << percent << "% of the crew was rescued.\n";
}
else if (main_option == 3)
{
cout << "\nThe Russians agree to send a rescue ship, but secretly attempt to hack into the ships systems remotely, which triggers an automatic shut down of all\ncommunications systems and locks all mission critical storage units, including\none of the storage unit that holds emergency oxygen tanks.\n\nOne quarter of all personnel are lost.\n";
}
else if (main_option != 1, 2, 3)
{
cout << "\nYou have been eaten by a Grue!\n";
}
}
int main()
{
cout << "Welcome to Gork 1.0\nCreated by Cortez Phenix\nTo make selections, enter the number of each option!\n\n";
int choice;
cout << "What would you like to do?\n1. Play Game\n2. Exit\nYour Choice: ";
cin >> choice;
if (choice == 1)
welcome();
else if (choice == 2)
cout << "\nGoodbye!\n";
else
cout << "\nPlease choose 1 or 2.\n";
return 0;
}
Excuse me. I'm sure this post is hectic.
IMAGE: At the bottom, you can see the queer number
If we do some slight reformatting on parts of your code, it looks like this:
if (crew_count <=4)
cout << "0% of crew members were rescued!\n";
else
float percent = calculatePct(crew_count, 4);
cout << percent << "% of the crew was rescued.\n";
The value you print is not the value calculated by calculatePct, it's the indeterminate value of the percent variable defined earlier in the function.
In short: You forgot your curly-braces:
if (crew_count <=4)
cout << "0% of crew members were rescued!\n";
else
{ // Note curly brace here
float percent = calculatePct(crew_count, 4);
cout << percent << "% of the crew was rescued.\n";
} // And also here
I recommend you enable more verbose warnings, as the compiler should be able to detect that you use the uninitialized variable, as well as the new variable being initialized but not used.
you mixed intergers and floats and void
int crew_count then you fed double menu(float crew_count).
your menu function doesnt return anything its supossed to be void so does your welcome function
Also you calculatePct does not return the calculated percentage. Do that by adding return percent;
See if it helps

How can I get an if-statement that takes multiple cin inputs to recognize an error if only the first cin input is incorrect?

I am building a program that is meant to store values from day-of-week/value pairs into a vector, and then display and sum the values for each day of the week. Therefore, I am asking the user to enter both a string (day of the week, which can be in 4 different forms for each day of the week) and an integer (a corresponding value) for each cin input. (The program only shows Monday and an exit condition so far; I will later build it out to include Tuesday through Sunday as well.)
The program is also meant to identify incorrect input (and allow the user to retry their input). However, I am having trouble getting the program to recognize erroneous input if only the day of week is entered incorrectly. For instance, the program will successfully announce "Incorrect day of week detected" if I enter "test test" as the input. It will also announce this message (even though the wording needs to be tweaked) if I enter "Monday x." However, if I enter "Test 5," the program accepts this without displaying the "Incorrect day of week" message.
How would it be possible to change my program so that, using the pre-existing else statement, it displays "Incorrect day of week" when I enter something like "Test 5"?
One solution would be to create a very long if statement that displays this message if the day of week entered does not match any of the 29 valid day-of-week entries (e.g. "Monday," "monday," "Mon," "mon," "Tuesday," "tuesday" . . . ). However, I would like to find a simpler approach.
Thank you for your help!
#include "../std_lib_facilities.h"
#include <iostream>
//Program in progress. Completing as part of my independent study of Programming: Principles and Practice by Bjarne Stroustrup.
int main()
{
string dayofweek;
int value;
vector<int> mondayvalues;
vector<int> tuesdayvalues;
vector<int> wednesdayvalues;
vector<int> thursdayvalues;
vector<int> fridayvalues;
vector<int> saturdayvalues;
vector<int> sundayvalues;
int incorrectentrycounter = 0;
int mondaysum = 0;
cout << "Please enter days of the week followed by values in integer form. When you are finished, please enter Done 0.\n";
string incorrectnumdump;
while (cin) {
if (cin >> dayofweek >> value) {
if (dayofweek == "Monday" || dayofweek == "monday" || dayofweek == "Mon" || dayofweek == "mon") {
mondayvalues.push_back(value);
}
if ((dayofweek == "Done") && (value == 0)) {
break;
}
}
else {
cin.clear();
cin >> incorrectnumdump;
cout << "Incorrect day of week detected; please try again.\n";
incorrectentrycounter++;
continue;
}
}
cout << "Here are the values you entered for each day of the week, along with their sums:\n";
cout << "Monday: ";
for (int x : mondayvalues)
cout << x << " ";
for (int i = 0; i < mondayvalues.size(); i++) {
mondaysum += mondayvalues[i];
}
cout << "\nSum of Monday values: " << mondaysum;
cout << "\nThere were " << incorrectentrycounter << "entries that displayed non-valid days of the week.";
}
Hmm.. Maybe you can use an ASCII technique to internally flip all inputs to either all caps or all small letters so that you won't have to look for both cases in your if statements as long as caps or small letters doesn't matter.
Make a function that takes the inputs and converts them to all caps or all small. Use this function before assigning the inputs to your variables. This will make checking them easier.
After that, you could create a const array[7] of std::string that will include all days. You can check your inputs by a method of elimination. You will be comparing input and array days letter by later and eliminating the days that don't match each time. If all days are eliminated then wrong input. If 2 or more days remain - input not sufficient. If 1 day remains that's the correct input!
Lemme know if you need help
After playing around with the code, I settled on this solution, which I think will meet my needs. The code now has two invalid entry statement blocks instead of one. The first ("Incorrect day of week detected") is within the if (cin >> dayofweek >> value) condition, and will identify dayofweek entries that don't match one of the Monday strings or Done.
The second ("Invalid entry") is outside the if (cin >> dayofweek >> value) condition but within the while (cin) condition. I added this second one so that if someone enters something like "test test," they will be notified of the error but the while loop will still continue.
So it seems as though when the user needs to enter multiple values via cin >>, one approach to input validation can be to enter multiple error messages at different levels of the code.
This solution is still a little clunky, but allows me to capture invalid entry with just "else" {} rather than "else" followed by a long set of conditions.
#include "../std_lib_facilities.h"
#include <iostream>
//Program in progress. Completing as part of my independent study of Programming: Principles and Practice by Bjarne Stroustrup.
int main()
{
string dayofweek;
int value;
vector<int> mondayvalues;
vector<int> tuesdayvalues;
vector<int> wednesdayvalues;
vector<int> thursdayvalues;
vector<int> fridayvalues;
vector<int> saturdayvalues;
vector<int> sundayvalues;
int incorrectentrycounter = 0;
int mondaysum = 0;
cout << "Please enter days of the week followed by values in integer form. When you are finished, please enter Done 0.\n";
string incorrectnumdump;
while (cin)
{
if (cin >> dayofweek >> value)
{
if (dayofweek == "Monday" || dayofweek == "monday" || dayofweek == "Mon" || dayofweek == "mon")
{
mondayvalues.push_back(value);
}
else if ((dayofweek == "Done") && (value == 0))
{
break;
}
else
{
cin.clear();
cin.ignore(10000, '\n');
cout << "Incorrect day of week detected; please try again.\n";
incorrectentrycounter++;
continue;
}
}
else
{
cin.clear();
cin.ignore(10000, '\n');
cout << "Invalid entry; please try again.\n";
incorrectentrycounter++;
continue;
}
}
cout << "Here are the values you entered for each day of the week, along with their sums:\n";
cout << "Monday: ";
for (int x : mondayvalues)
cout << x << " ";
for (int i = 0; i < mondayvalues.size(); i++)
{
mondaysum += mondayvalues[i];
}
cout << "\nSum of Monday values: " << mondaysum << "\n";
cout << "\nThere were " << incorrectentrycounter << " invalid entries.";
}

Need help in basic C++ regarding how to properly loop through part and finding smallest value

Hi I'm needing some help. I'm in a intro to programming class and we are using c++. I am hoping someone can help me with an assignment that was due yesterday (I understand not to expect miracle responses but a girl can always try).
I'm having two problems that I know of. The first is regarding the smallest value.
The big one is in trying to make it loop for requirements of three times but not lose out on my total count. I cannot use arrays or anything I haven't learned yet which is why I've posted this. I've seen similar problems and questions but they have ended up with answers too complex for current progress in class. So here is the problems instructions:
Instructions
1) Write a program to find the average value, the largest value, and the smallest value of a set of numbers supplied as input from the keyboard. The number of values in the data set must be in the range 0 to 20, inclusive. The user will first enter the number of values in the data set(use variable int Number). Give the user 3 attempts at entering Number in the range given. If the value for Number entered is out of this range, write an error message but continue. If the user does not enter a valid value for Number within the 3 attempts print an error message and terminate the program.
2) Format only the output for the Average value to 3 decimal places when printed.
3) The values in the data set entered as input can be any value positive, negative, or zero.
4) Make the program output readable(see the example below). (Note: that you will notprint out the input values that were entered in this program like you normally are required to do. This is because we have not covered the “tool” needed to do so yet in our studies).
Below will be the output from the execution of your program:
(using these values in order for the data set --> 19.0 53.4 704.0 -15.2 0 100.0)
The largest number: 704
The smallest number: -15.2
The average of the 6 numbers entered: 143.533
yourName L4p2XX.cpp
Lab#4 prob 2 XX-XX-12
Here is my poor excuse at the solution:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double Number = 0, minValue, maxValue, average, total = 0;
int ct = 0, numCount;
cout << "How many numbers would you like to enter? ";
cin >> numCount;
for(ct = 1; ct <= numCount; ct += 1)
{
cout << "Enter Value from 0 to 20, inclusive: ";
cin >> Number;
if(Number > 20|| Number < 0)
for(int errorCt = 1; errorCt <= 4; errorCt += 1)
{
if(errorCt == 4)
{
cout << "You have had 3 attempts to enter a valid" <<
"number. \nPlease try this program again when you" <<
"are able to follow directions.";
cout <<"\nLBn\n"<<"L4P2LB.cpp\n"<<"11-05-12\n";
return 0;
}
cout << Number << "is not within range.\n" <<
"Please enter a number from 0 to 20: ";
cin >> Number;
} //end for loop
total += Number;
if(maxValue <= Number)
maxValue = Number;
if(Number <= minValue)
minValue = Number;
} //end for loop
cout << "The smallest number entered was " << minValue << endl;
cout << "The largest number you entered was " << maxValue << endl;
average = total/numCount;
cout << setprecision(3) << fixed << showpoint << "You entered " <<
numCount << " numbers. The average of these is " << average;
//Program ID
cout <<"\n" << "L4P2LB.cpp\n" << "11-05-12\n";
system ("pause");
return 0;
} // End main
Thank you in advance to anyone who can steer me in the right direction. Not looking for anyone to do my work I just need help in direction if nothing else or any suggestions as to what to do. Thanks again. Lynda
Also I need somehow to pause after the third time and exit properly. If I put the second pause in it won't work so am I missing something obvious there too!
The first problem I see is that you didn't initialize a couple of variables.
You should either initialize both minValue and maxValue variables with something which will overwritten in every case in the first loop (typically "positive/negative infinity", as provided by <limits>), or just set both to Number in the first iteration, regardless of their current value. So I'd suggest to fix this by replacing
if(maxValue <= Number)
maxValue = Number;
if(Number <= minValue)
minValue = Number;
with
if(maxValue <= Number || ct == 1)
maxValue = Number;
if(Number <= minValue || ct == 1)
minValue = Number;
as ct == 1 will be true in the first iteration.
That said, you check the 0..20 range condition on the wrong variable. You check it on the Number variable, but you should check the numCount variable. But you also didn't respect the requirement that the variable to store the "number of numbers" should be Number, so you did check the correct variable, but used the wrong to read the input into. This should fix this issue (I changed the variable name in the cin >>... line + moved the check outside your main loop):
cout << "How many numbers would you like to enter? ";
cin >> Number;
if(Number > 20|| Number < 0)
{
for(int errorCt = 1; errorCt <= 4; errorCt += 1)
...
if(errorCt == 4)
{
cout << "You have had 3 attempts to enter a valid" <<
"number. \nPlease try this program again when you" <<
"are able to follow directions.";
cout <<"\nLBn\n"<<"L4P2LB.cpp\n"<<"11-05-12\n";
return 0;
}
cout << Number << "is not within range.\n" <<
"Please enter a number from 0 to 20: ";
cin >> Number;
} //end for loop
}
for(ct = 1; ct <= Number; ct += 1)
{
...
}
...

Is there a way to not include a negative number in an average, when entering a negative number is how you terminate the program?

Sorry about last time for those who saw my previous thread. It was riddled with careless errors and typos. This is my assignment:
"Write a program that will enable the user to enter a series of non-negative numbers via an input statement. At the end of the input process, the program will display: the number of odd numbers and their average; the number of even numbers and their average; the total number of numbers entered. Enable the input process to stop by entering a negative value. Make sure that the user is advised of this ending condition."
And here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int number, total1=0, total2=0, count1=0, count2=0;
do
{
cout << "Please enter a number. The program will add up the odd and even ones separately, and average them: ";
cin >> number;
if(number % 2 == 0)
{
count1++;
total1+=number;
}
else if (number >= 0)
{
count2++;
total2+=number;
}
}
while (number>=0);
int avg1 = total1/count1;
int avg2 = total2/count2;
cout << "The average of your odd numbers are: " << avg1 << endl;
cout << "The average of your even numbers are " << avg2 << endl;
}
It seems to be working fine, but when I enter a negative number to terminate the program, it includes it with the rest of the averaged numbers. Any advice to get around this? I know it's possible, but the idea escapes me.
Your main loop should be like this:
#include <iostream>
for (int n; std::cout << "Enter a number: " && std::cin >> n && n >= 0; )
{
// process n
}
Or, if you want to emit a diagnostic:
for (int n; ; )
{
std::cout << "Enter a number: ";
if (!(std::cin >> n)) { std::cout << "Goodbye!\n"; break; }
if (n < 0) { std::cout << "Non-positve number!\n"; break; }
// process n
}
After here:
cout << "Please enter a number. The program will add up the odd and even ones seperately, and average them: ";
cin >> number;
Immediately check if the number is negative
if(number < 0) break;
Now you wouldn't need to use your do-while loop in checking if the number is negative. Thus, you can use an infinite loop:
while(true) {
cout << "Please enter a number. The program will add up the odd and even ones seperately, and average them: ";
cin >> number;
if(number < 0) break;
// The rest of the code...
}
ADDITIONAL:
There is something wrong in your code. You aren't showing the user how much the number of even and odd numbers are, and the total number of numbers entered.
ANOTHER ADDITIONAL: You should use more meaningful variable names:
int totalNumEntered = 0, sumEven = 0, sumOdd = 0, numEven = 0, numOdd = 0;
Of course I am not limiting you to these names. You can also use other similar names.
FOR THE INTEGER DIVISION PROBLEM:
You must cast your expression values to the proper type (in this case, it is float). You should also change the averages variables' types to float:
float avg1 = float(total1) / float(count1);
float avg2 = float(total2) / float(count2);
Immediately after cin >> number, check for < 0, and break if so. Try to step through the program line by line to get a feel for the flow of execution. Have fun learning, and good luck!