Program wont run. need suggestion

#include <iostream>
using namespace std;

int main ()
{

char operation,operation2;
float i;
int num1,num2;

cout<<" \nPlease enter the first number that you would like to calculate- " ;
cin >> num1 ;
cout <<"\nPlease enter the second number that your would like to calculate- " ;
cin>> num2 ;
cout <<endl ;
for (int i=1; i<=11;i++)
{

}

cout <<"\nPlease enter arithmetic operation that you would"
<< "like to work with such as; + or - or / or * or % " ;
cin >> operation ;
while (+==0 || -==0||*==0) && ( /==0 || %==0)
{
cout << "Please enter a valid operator";
cin >> operation2;
}


switch ( operation )
{
case '+' :
cout <<" The addition of two numbers is "
<<num1+num2<<endl ;
break;
case '-':
cout<<" The subtraction of two numbers is "
<<num1-num2<< endl ;
break;
case '*':
cout<<" The product of two number is "
<<num1*num2<<endl ;
break;
case'/':
cout<< "The division of two number is "
<<num1/num2 ;
break;
while (num2 ==0);
{
cout<< "\nDivision by zero is invaid. Please enter a value other zero";
cin>>num2 ;
break;
}
case'%':
int %
cout <<"The remaing factor of your two number is "
<<num1%num2;
break;
while (num2 ==0)
{
cout <<"\nModule less than zero is invalid. Please enter a value other zero";
cin>>num2;
}
while (operation ==0)
{
cout<< "input invalid"
<<"Please re-enter operation";
cin>> operation2;
}
}




system ("pause");
return 0;
}
Your program has compiler errors. Of course it cannot run.
You should use code tags. And indent your code so that it is easier to read.

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;

int main()
{
	int i;
	char operation;
	double num1, num2;

	cout<<"Please enter the first number that you would like to calculate : " ;
	cin >> num1 ;
	cout <<"Please enter the second number that your would like to calculate : " ;
	cin>> num2 ;
	cout << endl;

	cout << "Please enter arithmetic operation that you would" << endl;
	cout << "    like to work with such as : '+', '-', '/', '*', '%' : " ;
	cin >> operation ;
	while (operation != '+' && operation != '-' && operation != '*' && operation != '/' && operation != '%')
	{
		cout << "Please enter a valid operator : "; cin >> operation;
	}

	switch (operation)
	{
		case '+' :
		cout <<" The addition of two numbers is : " << num1 + num2 <<endl ;
		break;
		case '-' :
		cout<<" The subtraction of two numbers is : " << num1 - num2 << endl ;
		break;
		case '*' :
		cout<<" The product of two number is : " << num1 * num2 << endl ;
		break;
		case '/' :
		if (num2 == 0.0)
		{
			cout<< "Divide Error : Division by zero is invalid." << endl;
		}
		else
		{
			cout<< "The division of two number is : " << num1 / num2 << endl;
		}
		case '%' :
		cout << "The remaing factor of your two number is : " << int(num1) % int(num2) << endl;
		break;
	}

	system ("pause");
	return 0;
} 
1
2
3
4
for (int i=1; i<=11;i++)
{ 

}

This will only cause a delay of 10 cpu cycles. Assuming a modern computer that should be a delay of less then 0.0001ms. But because computers run multiple programs at the same time the duration of the delat will be very unstable.

while (+==0 || -==0||*==0) && ( /==0 || %==0)
+ is not a variable, it is a function that requires two variables and you provide non.
- is not a variable, it is a function that requires two variables and you provide non.
* is not a variable, it is a function that requires two variables and you provide non.
/ is not a variable, it is a function that requires two variables and you provide non.
% is not a variable, it is a function that requires two variables and you provide non.
This is very unlikely to compile. I would expect that you intended to compare characters and forgot the quotes, but then you get comparisons with only constants which is extremely useless and therefor unlikely.

What is your intention with this code?
@SakurasouBusters -Thank you


@Nico;

For (int i=1.....)
{
}
I wanted to create a loop that made the program run 10 times

what I wanted to do with the while loop is ensure the user only selected the assigned mathematical operation if he or she did not it would present the user with an error message. I did forget the single quote but I also do not understand how to properly assemble one

I wanted to create a loop that made the program run 10 times
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;

int main()
{
	int i;
	char operation;
	double num1, num2;

	for(i = 0; i < 10; i++)
	{
		cout << i + 1 << "." << endl;
		cout<< "Please enter the first number that you would like to calculate : " ;
		cin >> num1 ;
		cout << "Please enter the second number that your would like to calculate : " ;
		cin >> num2 ;
		cout << endl;

		cout << "Please enter arithmetic operation that you would" << endl;
		cout << "    like to work with such as : '+', '-', '/', '*', '%' : " ;
		cin >> operation ;
		while (operation != '+' && operation != '-' && operation != '*' && operation != '/' && operation != '%')
		{
			cout << "Please enter a valid operator : "; cin >> operation;
		}

		switch (operation)
		{
			case '+' :
			cout <<" The addition of two numbers is : " << num1 + num2 <<endl ;
			break;
			case '-' :
			cout<<" The subtraction of two numbers is : " << num1 - num2 << endl ;
			break;
			case '*' :
			cout<<" The product of two number is : " <<num1 * num2 << endl ;
			break;
			case '/' :
			if (num2 == 0.0)
			{
				cout<< "Divide Error : Division by zero is invalid." << endl;
			}
			else
			{
				cout<< "The division of two number is : " << num1 / num2 << endl;
			}
			case '%' :
			cout << "The remaing factor of your two number is : " << int(num1) % int(num2) << endl;
			break;
		}

		system ("pause"); cout << endl;
	}
	return 0;
} 
@SakurasouBusters
I just learned something new !!...Thank you.
"cout << i+1<< "." <<endl;

makes the output look neat
Last edited on
Topic archived. No new replies allowed.