Alright, I need a program that has both a selection structure and a repetition structure. Would someone please tell me if I am doing this right. My code gives me the correct output but do I have a selection and repetition structure?

``````#include <iostream>
using namespace std;
int main ()
{
// variables
double incomes = 0.0;
double spending = 0.0;
int totalIncome = 0;
int totalSpending = 0;
int subTotal = 0;
int grandTotal = 0;
int counterIncome = 1;
int counterSpending = 1;

while (incomes >= 0)
{
totalIncome += incomes;
cout << "Enter week " << counterIncome << " income value (negative value to stop):  ";
cin >> incomes;
counterIncome += 1;
}
while (spending >= 0)
{
totalSpending += spending;
cout << "Enter week " << counterSpending << " spending value (negative value to stop):  ";
cin >> spending;
counterSpending += 1;
}
counterIncome += 1;
grandTotal = totalIncome - totalSpending;
//diaplay subtotal and grandtotal
cout << "Subtotal Income is: \$ " << totalIncome << endl;
cout << "Grand Total Profit is: \$ " << grandTotal << endl;
return 0;
}
``````

What do you mean you need an selection structure? Are you talking about a switch statement?

## All 4 Replies

What do you mean you need an selection structure? Are you talking about a switch statement?

I guess yes I am talking about a switch statement. Then this is wrong code for that.

That's assuming a selection structure means a switch statement. Since we don't know the context of your terms, it's hard to say with accuracy.

I dont see anything wrong with your code, it is beutifull. I might just use this for myself... but anyway WaltP is right... We dont know the context of your code...

If it is a switch statement, then you can add one. It will just be a little longet and maby harder. But just a little. The code seems to do its job like this so its up to you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.