I want to use my own program on other computer;

#include<iostream>
using namespace std;
void main()
{
cout<<"it's a number like this\"x+x+\(x/2\)+5+10=70\" so what is it: ";
int x;
cin>>x;
for(int i=1;i!='\0';i++){
if((((x+x)+(x/2))+15)==70)
{cout<<x<<" yes u r right "<<endl;
break;}
else
{cout<<"try again.\n";
cin>>x;
}}}

Last edited on
First off, what are you asking? Second, this is some ugly looking code.
closed account (zb0S216C)
First, format your code. Second, test your program on another computer. It's as simple as that.

Wazzak
The coding is horrible and far from correct. Your loop never ends: why would 'i' ever become '\o'? It's not a char, it's not input, so why would it?

Secondly, '}}}' clearly points to a lack of structure. Your else, for and main end on the same line. Is that good? Maybe. Is it clear? Oh no.

Lastly, nobody knows what your question is. If you want to use it on another computer, first make sure it works on YOUR computer. Right now, it sure as hell won't.

[edit]

Actually, it might. You WANT the loop to be infinite? Then put an empty for instead of this weirdness.
Last edited on
Instead of that for loop, it might be better to use a do/while loop. It makes it a lot easier to understand. And also, have the instructions that you put on screen, a little more descriptive of what is expected from the user. I think this coding helps the user a lot more..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>

using namespace std;

void main()
{
	int x;
	cout<<"Here is the equation : x+x+(x/2)+5+10 = 70." << endl << "What is 'x' equal to? : ";
	do
	{
		cin>>x;
		if((x+x)+(x/2)+15 == 70)
		{
			cout<<x<<". Yes u r right "<<endl;
			cout << x << "+" << x << "+" << "(" << x/2 << ")+5+10 is equal to " << x+x+(x/2)+5+10 << "..." << endl << endl;

			break;
		}
		else
		{
			cout << "Sorry.. " <<  x << "+" << x << "+" << "(" << x/2 << ")+5+10 is equal to " << x+x+(x/2)+5+10 << "..." << endl << endl;
			cout<<"Please try again." << endl << endl;
		}
	} while ((x+x)+(x/2)+15 != 70);
}
Topic archived. No new replies allowed.