Ok so the code makes the user type in a number. Ok if the number is odd it must say "Invalid Input". If the number is even it takes the ODD numbers of it and gives you the sum, but doesn’t display it ( I don't want the sum to be displayed).
Example: if you type in 10 it goes 1 + 3 + 5 + 7 + 9
that gives me 25 which is good the program gives me 25 which is good, but for the program I want the added pairs to show up that add to that number(the input).
For example if I type 8
I want
8 = 1 + 7
8 = 3 + 5
to show up how do I do that?
I get the sum how do I get the added pairs to show up?
Here is the code
Code:#include <iostream> using namespace std; int main() { int sum = 0; int num; cout << " Please enter a positive even interger "; cin >> num; if ( num % 2 != 0 ) cout << "Invalid Input" << endl; else if ( num % 2 == 0 ) { for ( int i = 1; i <= num; i++ ) { if ( i % 2 != 0 ) sum += i; } if ( ( i == sum ) && ( i != i ) ) cout << 8 << " = " << i << " + " << i << endl; cin >> num; } return 0; }
I have error for some reason?
test.cc:29: error: name lookup of âiâ changed for new ISO âforâ scoping
test.cc:20: error: using obsolete binding at âiâ



LinkBack URL
About LinkBacks



