Help me with this program

Hello Good night. I'm Beginner and I've received this program to do its due tonight and i'm still having problem doing it. Could someone help me please??

Write a program to continue accepting integer numbers while the number entered is NOT 999. The program should store each number in an array called "numbers" (no more than a 100 numbers will be used). After accepting all the numbers, the program should prompt the user for the operation to be performed.

If the user enters "+" for the operation the program should find the sum of all the numbers as the result, however, if the user enters "x" for the operation, the program should find the product of all the numbers as the result.

Afterwards, if the user entered "+" for the operation, the program should then print all the numbers previously entered followed by the operation in the following manner:

Example: The numbers entered were 3, 5, 10, 999 and the operation entered was "+" :
The sum of 3, 5 and 10 is 18.
If the user entered "x" for the operation, the program should then print the output in the following manner:

Example: The numbers entered were 3,5, 10, 999 and the operation entered was "x":
The product of 3, 5 and 10 is 18.

Finally, if the operation entered was not “+” or “x”, the program should print “You have entered an invalid operation, please run the program and try again.”
very simple program
i shouldn't have to do your whole homework for you
try something first then edit your post with what you have
you should be able to do a switch statement tho
Last edited on
I just started programming to be honest i understand little so far but i'm going to show you what i've been doing so far


#include<iostream>

using namespace std;

int main()
{
//write a program to continue accepting integer numbers while the number entered is not 999.
//the program should store each number in an array called numbers.
int numbers[3]; (6, 12, 10, 999);

//After accepting all the numbers, the program should prompt the user for the operation to be performed.
//if the user enters "+" for the operation the program should find the sum of all the numbers.
//if the user enters "+" for the operation, the program should then print all numbers previously


int product;
int sum;

if ('+'); {
sum = 6 + 12 + 10;
cout<< "sum of all numbers is: \n";
cin >> sum;

}

if ('*'){
product = 6 * 12 * 10;
cout<< "product of all number is: \n";
cin>> product;

}





// Finally, if the operation entered was not "+" or "x", the program should print " You have entered an invalid operation, please run the program and try again."

return 0;

}
Last edited on
int numbers[3]; (6, 12, 10, 999); //the numbers in () are nonsense in c++.
did you mean

int numbers[4] = {6, 12, 10, 999}; //this makes numbers contain those values.


if ('+'); { //this is simply true. what you probably mean is something like this:

char ch;
cout << "enter + or -" << endl;
cin >> ch;

if(ch == '+')
{ ...

and you should use numbers array somewhere or not have it.

else
if(ch == '*')
{
...
else
cout << "bad input" << endl;


you have a bit to do... you need to loop to read numbers until 999 is typed, but get it working with the hard-coded values first, little by little...
Last edited on
ok thanks. I'm going to loop it now
sigh. I'm still stuck

int main()
{
int numbers[4] = {6, 12, 10, 999}; //this makes numbers contain those values.
int sum=0;

char ch;
cout << "enter + or -" << endl;
cin >> ch;

if(ch == '+')
{
int numbers[4], i, sum = 0;
clrscr();

else
if(ch == '*')
{
cout<<"add";
}else
cout << "bad input" << endl;


return 0;

}
Last edited on
There's an example of finding the sum of all the values in an array in the tutorial, under the heading Accessing the values of an array
http://www.cplusplus.com/doc/tutorial/arrays/

It uses a for-loop. If necessary, you can find more details about how loops work under the heading, The for loop in the tutorial:
http://www.cplusplus.com/doc/tutorial/control/

Given the limited time available for completing this assignment, you may need to do a more detailed reading of those pages later. But for now concentrate on the array example, the one with the line
 
    int foo [] = {16, 2, 77, 40, 12071};
and the result 12206.
ok thank you so much that information
int numbers[4], i, sum = 0; //this re-declares the same variables you already have.

you want something like

if(ch == '+')
{
int i = 0;
while (numbers[i] != 999)
sum += numbers[i++];
}

note that if you use this technique for products, start product at 1 not zero :P
Last edited on
Topic archived. No new replies allowed.