My first post.
I am trying to learn C++ and have been reading the tutorials (learn something! Presidential order…seams reasonable). Books are on the way. Anyway, as an exercise, I’ve taken some of the tools presented here and put them into one thing.
Code:
#include <iostream>
using namespace std;
int a;
void playgame()
{
cout << "Play";
}
int main()
{
for (;a=1;)
{
int input;
cout<<"1. Multiply\n";
cout<<"2. Devide\n";
cout<<"3. Add\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> input;
switch (input)
{
case 1:
playgame();
cout<<" Multiplication\n";
{float mult ( int x, int y );
float x;
float y;
cout<<"Please input two numbers to be multiplied: ";
cin>> x >> y;
cin.ignore();
cout<<"The product of your two numbers is "<< x * y <<"\n";
a=1;
}
break;
case 2:
playgame();
cout<<" Devision\n";
{float div (int x, int y);
float x;
float y;
cout<<"Please enter a number for a dividend and a number for a devisor: ";
cin>> x >> y;
cin.ignore();
cout<<"The quotent is "<< x / y <<"\n";
a=1;
}
break;
case 3:
playgame();
cout<<" Addition\n";
{float add (int x, int y);
int x;
int y;
cout<<"Please enter two numbers to add: ";
cin>> x >>y;
cin.ignore();
cout<<"The result is "<< x + y <<"\n";
a=1;
}
break;
case 4:
cout<<"Thank you for playing!\n";
break;
a=0;
default:
a=0;
cout<<"Error, bad input, quitting\n";
break;
}
cin.get();}
cout<< a <<endl;
}
Ok, it kinna sorta does what I expected. BUT! I expected it would quite automatically if case 4 were in play. It doesn’t. It just continues to loop. Same with default.
Any hint about what I’m missing? I’ve tried sooooo many things, too many to list here.
Thanks,
Sug