Ok, in my C++ Console Project, I am prompting the user to make a choice of multiplication, addition, subtraction, or division, and then enter two numbers to perform the selected operation. But I am having some syntax errors I am not sure how to fix. Here is my code:
[code=cpp]
#include "stdafx.h"
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
using namespace std;
void Wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
int main( void )
{
//variables
int number1;
int number2;
int answer;
char choice;
char keepplaying = "y";
//code
while(keepplaying == "y")
{
cout << "Enter your choice of math (+ , - , /, x): ";
cin >> choice;
if(choice = "+")
{
cout << "Enter two numbers to add together:" << endl;
cin >> number1;
cout << "+" << endl;
cin >> number2;
cout << endl;
answer = number1 + number2;
cout << endl << "Calculating...";
Wait( 5 );
cout << " ... Done Calculating! Your answer is... " << answer << endl << endl;
system("PAUSE");
}
else if(choice = "-")
{
cout << "Enter two numbers to subtract:" << endl;
cin >> number1;
cout << "-" << endl;
cin >> number2;
cout << endl;
answer = number1 - number2;
cout << endl << "Calculating...";
Wait( 5 );
cout << " ... Done Calculating! Your answer is... " << answer << endl << endl;
system("PAUSE");
}
else if(choice = "/")
{
cout << "Enter two numbers to divide:" << endl;
cin >> number1;
cout << "/" << endl;
cin >> number2;
cout << endl;
answer = number1 / number2;
cout << endl << "Calculating...";
Wait( 5 );
cout << " ... Done Calculating! Your answer is... " << answer << endl << endl;
system("PAUSE");
}
else if(choice = "x")
{
cout << "Enter two numbers to add together:" << endl;
cin >> number1;
cout << "x" << endl;
cin >> number2;
cout << endl;
answer = number1 * number2;
cout << endl << "Calculating...";
Wait( 5 );
cout << " ... Done Calculating! Your answer is... " << answer << endl << endl;
system("PAUSE");
}
else
{
cout << "That is not a valid option." << endl << endl << endl << endl;
}
cout << "Play again? (Y/N)" ;
cin >> keepplaying;
}
}
[/code]
And here is the build log.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
1
|
1>Compiling...
1>Test.cpp
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(24) : error C2440: 'initializing' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(26) : error C2446: '==' : no conversion from 'const char *' to 'int'
1> There is no context in which this conversion is possible
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(26) : error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(30) : error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(43) : error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(56) : error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>c:\documents and settings\brad\my documents\visual studio 2008\projects\test\test\test.cpp(69) : error C2440: '=' : cannot convert from 'const char [2]' to 'char'
1> There is no context in which this conversion is possible
1>Build log was saved at "file://c:\Documents and Settings\Brad\My Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm"
1>Test - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== | |
I am using Windows with Microsoft Visual C++ 2008 Express Edition. This is a console project.