OK, im making a simple subtraction/addidtion proggram from homework and at the beggining of the program there has to be a choice to go into a sub calculator that only adds or divides. this is what i got so far.(yes i know i write really,really, wierd. Iwas taught this way)
#include<iostream>
int main()
{
using namespace std;
float a,b,sum;
char choice1;
char choice2 = 'y';
while (choice2 == 'y')
{
cout << endl;
cout << "Calculator Program [V1.01]";
cout << endl << endl;
cout << "Choose Operation Type ";
cout << endl;
cout << "Addition=A Subtraction=s";
cout << "a or s: ";
cin >> choice1
if (choice1 == 'a')
{
cout << "Enter First Number: ";
cin >> a;
cout << "Enter Second Number: ";
cin >> b;
sum = a + b;
cout << endl;
cout << "The Sum Is " << sum;
cout << endl;
#include<iostream>
usingnamespace std; //<-moved outside of int main
int main()
{
float a, b, sum;
char choice1;
char choice2 = 'y';
while(choice2 == 'y')
{
cout << endl;
cout << "Calculator Program [V1.01]";
cout << endl << endl;
cout << "Choose Operation Type ";
cout << endl;
cout << "Addition = a Subtraction = s";
cout << endl; //<-otherwise it was messy
cout << "a or s: ";
cin >> choice1; //<-added semicolon
if (choice1 == 'a')
{
cout << "Enter First Number: ";
cin >> a;
cout << endl; //<-otherwise it was messy
cout << "Enter Second Number: ";
cin >> b;
sum = a + b;
cout << endl;
cout << "The Sum Is " << sum;
cout << endl;
cout << endl;
cout << "Try Again? [y/n] ";
cin >> choice2;
}
else{
return 0;
}
}
return 0;
}
Made a few small changes (where noted). Your program runs just fine so far. I suggest you change the variable of your while loop, however. As it is now, when prompted to "try again" the user can enter anything other than 'y' and it will end the loop.