Basically my program is to allow the user to enter as many integers as wanted, positive or negative, and then after each input display if the number is odd or even. I know how to do these each separately, but i don't know how to make it to do both the adding and displaying of odd or even after each input.
Here is my code
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
float num1;
float num2;
char sign;
float result = 0;
start:
cout << "Enter an integer" << endl;
cin >> num1;
cout << "enter another number" << endl;
cin >> num2;
do
{
cout << "press = to finish" << endl;
cin >> sign ||num2;
result = num1 += num2;
cin >> sign ||num2; ¿what do you think you are doing there?
> but i don't know how to make it to do both the adding and displaying of odd or even
that's the first time you mention adding...
so you know how to do
1 2 3 4 5 6 7
total := 0
while read input:
total := total + input
if is_even(total): //¿or do you want to test input?
print("even")
else:
print("odd")
#include <iostream>
// #include <cmath>
#include <string>
usingnamespace std;
int main()
{
float num1 = 0.;
float num2 = 0.;
char sign = 'c';
float result = 0.;
int TEMP = 0;
while
(
cout << "Press c to continue or = to quit: " &&
cin >> sign &&
sign != '='
)
{
cout << "Enter an integer: "; // ambiguous given num1 is a float
cin >> num1;
TEMP = num1;
if (num1 - TEMP != 0)
cout << num1 << " is not an integer\n";
elseif (TEMP % 2 == 0)
cout << num1 << " is even\n";
else
cout << num1 << " is odd\n";
cout << "Enter another number: ";
cin >> num2;
result += (num1 + num2);
}
cout << "The running total is: " << result << endl;
return 0;
}
Press c to continue or = to quit: 12
Enter an integer: 2 is even
Enter another number: 8
Press c to continue or = to quit: c
Enter an integer: 7
7 is odd
Enter another number: 8.9
Press c to continue or = to quit: =
The running total is: 25.9
Program ended with exit code: 0