HEY EVERYONE...SO I HAVE THIS ASSIGNMENT THAT I'M COMPLETELY STUCK ON...ANY HELP WOULD BE APPRECIATED...
THIS IS THE ASSIGNMENT:
Part 1
Set up a simple program that prompts the user to enter a series of positive integer numbers between 50 and 100 (inclusive) using the keyboard. Your prompt should tell the user to enter a negative number to stop the input process.
As the user enters the numbers, you should keep track of the number of valid entries they have made (those that fall in the allowed range), and add up those numbers entries. You do not need to store more than the single entered number, the count, and the current total you are calculating.
Once the user completes the data entry, produce output similar to this:
A total of 5 values were entered.
The sum of those numbers is 127
Part 2
For this part, you will add a block of code to the program you wrote in part 1. Place the new code below the point where you generated the output. As you test this code, just enter a single negative number to get past the first part of the program.
Write this part one step at a time.
Step 1
Set up a while-loop that modifies a variable named number so that it has a value that increases from 1 to 9. Test it by printing out the number.
Step 2
Add an if-then-else statement inside the loop, right above the output statement you used to test step 1 above. This statement should test the value of number and assign a value of number to a new variable called star_number if the value of number is less than 6, otherwise set star_number to 10 - ``number. Test this step by again printing out both number and start_number.
Step 3
Finally, replace your output statement (the one you used in testing) with a chunk of code that prints out exactly star_number star characters (the symbol we use for multiplication).
To do this, use a for loop that prints out a single star character inside the loop. After the right number of stars have printed, add a statement that sends an endl to the output to complete the line.
Your final output should look like this:
*
**
***
****
*****
****
***
**
*
THIS IS WHAT I HAVE:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int number = 0;
int totalNumbers = 0;
double sum = 0.0;
int num2 = 1;
int star_number;
do
{
cout << "Enter a number between 50 and 100 or -1 to Exit: " << endl;
cin >> number;
totalNumbers = totalNumbers + 1;
sum = sum + number;
if (number == -1)
{
cout << "A total of " << totalNumbers - 1 << " values were entered.";
cout << "The sum of those numbers is " << sum + 1 << endl;
}
} while (number >= 50 && number <= 100);
while (num2 <= 9)
{
if (num2 < 6)
{
num2 = star_number;
}
else if (num2 > 6)
{
star_number = 10 - num2;
}
cout << num2 << endl;
num2++;
}
system("PAUSE");
return 0;
}
COMPLETELY STUCK...ANY HELP WOULD BE APPRECIATED AGAIN, THANKS IN ADVANCE!
What exactly is your problem?
(You might be under programmer stress which is causing you not to see possibly tiny (but significant) errors in your program)
Plus why are you not checking whether the user input is within range when its entered?while (number >= 50 && number <= 100); You could do an if statement to test whether its in range, before summing it; plus additionally you could only add it to your sum in the if statement, which would be occurring whilst its valid.
Tip: be specific about your problem so its easier for helps to be given. This is just because of the simple fact that there are a billion and one ways to program