You also need to initialize total to zero before you start adding values to it.
You also need to initialize total to zero before you start adding values to it.
Mainframe assembler programmer by trade. C coder when I can.
An IF condition must be enclosed in parens. Your curly braces surrounding the last two IF statements are not necessary.
Mainframe assembler programmer by trade. C coder when I can.
How about:
Code:#include <iostream> using namespace std; int main() { int num1; int num2; cout << "Please enter an integer between 0 and 100: "; cin >> num1; cout << "Please enter an integer between 50 and 100: "; cin >> num2; int total; for(int counter=num1;counter<num2;counter++) { total+=counter; } { if (num1 < 1 || num1 > 100) cout << "Please read and follow the directions!" } { if (num2 <50 || num2 >100) cout << "Please read and follow the directions!" } cout << "The total of the intergers between " << num1 << " and " << num2 << " is " << total << end;
no, that's still wrong.
you should at least try to compile your program before just asking the internet to fix your mistakes.
Code:int main () { if (condition is true/*all other if's will be ignored*/) {do stuff - if it is true} else if (if condition if isn't true look here/*all other if's will be ignored*/) // 1. else if {do stuff - if it is true} else if (if condition else if /*1. else if*/isn't true look here) {do stuff - if it is true} else // if all if's aren't true use this {do stuff - always if all other if's aren't true} return 0; // don't forget on this one } // don't forget for this one you must close the braces // if you put this in compiler you'll get a lot of errors // I tried to put it in to human like to understand not computer
Last edited by military genius; 10-14-2009 at 11:22 AM.
thank you for your help. the situation I am in doesn't allow me access to a compiler. so i am trying to make due with doing this the best I can.
So I cannot use this?
Code:{ if (num1 < 1 || num1 > 100) cout << "Please read and follow the directions!" } { if (num2 <50 || num2 >100) cout << "Please read and follow the directions!" }
Last edited by Titanguy; 10-14-2009 at 11:38 AM.
aghhh, I am stuck
coding without a compiler is like drawing with no pencil.
you need one. period.
this is just false.the situation I am in doesn't allow me access to a compiler. so i am trying to make due with doing this the best I can.
visual studio express is free, gcc is free, many others are free. get one. install it. compile.
I just found an online compiler
Ok, here is what I came up with now:
Code:#include <iostream> using namespace std; int main() { int num1; int num2; cout << "Please enter an integer between 0 and 100: "; cin >> num1; cout << "Please enter an integer between 50 and 100: "; cin >> num2; int total = 0; for(int counter=num1;counter<num2;counter++) { total+=counter; } if (num1 < 1 || num1 > 100) cout << "Please read and follow the directions!"; if (num2 <50 || num2 >100) cout << "Please read and follow the directions!"; cout << "The total of the intergers between " << num1 << " and " << num2 << " is " << total << endl; }
You can use GCC/G++ without making any changes to the computer you're using.
Download MinGW (be sure to check the box for g++ and make if you need it) and copy the MinGW directory to a flash drive.
On the computer you're going to be using, put in the flash drive, open up a cmd.exe (hit winkey+r and type cmd) and type
set path=%path%;E:\MinGW\bin
(Use the appropriate drive letter and path)
You're good to go!
I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo
how do you start the program?
after I set the path, how do I set the path back to original?
It didn't work. no big deal, but I set the path to:
set path=%path%;E:\MinGW\bin
How can I undo that, so nothing is changed on the computer?