Well second day of class and needless to say I am more than rusty after taking a year and a half off ne how I am getting two errors when I am compiling and I can't figure them out. This calc is supposed to generate two random numbers and the user picks what he wants to do w/them and then he answers it then the program tells him if he is right or wrong.
Thanks for the help in advance :-)
Code:
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<time.h>
double Add (double a, double b) //Addition
{
cout << a << " + " << b << " = ";
return (a+b);
}
double Multiply (double a, double b) //Multiplcation
{
cout << a << " * " << b << " = ";
return(a*b);
}
double Subtract (double a, double b) //Subtraction
{
cout << a << " - " << b << " = ";
return(a-b);
}
double Divide (double a, double b) //Dividing
{
cout << a << " / " << b << " = ";
return(a/b);
}
double main()
{
int num1;
int num2;
int choice;
int stop;
int ans;
int usans;
stop = 1;
while(stop < 2)
{
cout << "C++ Assigment Two - Random Calculator" << endl;
cout << "\n";
srand(time(0)); //this will produce a new number after each execution.
num1 = 1+rand()%20;
num2 = 1+rand()%20;
cout << "Do you wish to: (1)Add, (2)Subtract, (3)Multiply or (4)Divide ?" << endl;
cin >> choice;
switch (choice) //Calculator Function
{
case 1: cout << num1 << "+" << num2;
ans = num1 + num2;
break;
case 2: cout << num1 << "x" << num2;
ans = num1 x num2;
break;
case 3: cout << num1 << "-" << num2;
ans = num1 - num2;
break;
case 4: cout << num1 << "/" << num2;
ans = num1 / num2;
break;
}
cin >> usans;
If (ans == usans)
{
cout<< "/nYour answer is correct"
}
else
{
cout << "/nIncorrect Answer"
}
cout <<"\n\nDo you wish to (E)xit or (R)estart";
char ch;
cin >> ch;
//this if statment will keep looping untill they enter E or e...
if(ch == 'E' || ch == 'e') stop = 2;
clrscr();
}
}