0

What I want is when I type "calc;" (without quotes), The calculator opens. Else, if I didn't type it correctly (example: "calc" (without quotes)) it will generate an error.

#include <iostream>
#include <string>

using namespace std;

int main () 
{
	string calc;
	char end;
	end = ';';

	cin >> calc >> end;

	if(calc == "calc") 
	{
		system("calc");
	} 
	else 
	{
		cout << "Error..." << endl;
	}
	return 0;
}
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Tom_Weston
0

Line 12.

Why are you doing this

cin >> calc >> end;

Why >> end;

Is this what your trying to accomplish?

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main () 
{
	string calc;

	cin >> calc;

	if(calc == "calc") 
	{
		system("calc");
	} 
	else 
	{
		cout << "Error..." << endl;
	}
	return 0;
}

Edited by gerard4143: n/a

0

you forgot the ';' in:

...
//HERE - > calc == "calc;"
	if(calc == "calc") 
	{
		system("calc");
	} 
	else 
	{
	...

and also you have to include the <stdlib.h> header. without it you can't use "system"

0

Thanks, works perfectly!

But the main purpose of the 'end' was a ending character ';' not endl which ends the line. But this works as well, thanks to both of you! Any reputation system or award?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.