Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 27, 2016 6:39:24 GMT
I wanted to try out your suggestion that if I type strings on my int variable then ask for it again. Well I am not sure if this is really easy, but I don't know how to check if the variable has strings or integers in it.
Code:
using namespace std;
int main(){ int firstNum; int secondNum; string Answer = "No"; while(Answer != "Yes" && Answer == "No"){ //I used your suggestion and tried to find other ways than goto. cout << "\nHi! Pick two numbers and multiply\n1st:" << endl; cin >> firstNum; cout << "\n2nd: " << endl; cin >> secondNum; cout << "\nAnswer equals " << firstNum*secondNum << "\nQuit?\n" << endl; cin >> Answer; if(Answer == "Yes"){ cout << "\nBye" << endl; Sleep(1000); }else if(Answer != "No" || Answer != "Yes"){ cout << "\nQuit?\n" << endl; cin >> Answer; } } }
|
|
|
Post by TheCreator on Feb 27, 2016 17:57:11 GMT
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 27, 2016 18:17:47 GMT
I have looked into that before posting here. This link was a better one though en.cppreference.com/w/cpp/string/basic_string/stol thx anyways :) the example was a lot more simpler than the other sites I looked into. I was confused if they typed, "jdial" it convert it into numbers so I wanted to check here, but the site that gave the example gave a string and numbers, but only numbers was put into the new variable.
|
|
|
Post by TheCreator on Feb 27, 2016 18:49:04 GMT
In that case, if you just want to find out if the input was a string our number you can use isdigit(), which returns true if the supplied char is a number and false if it isn't.
|
|