|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
While Loop Error
I am very new at programming in general, but I tend to pick up things by following examples...
Anyways, I have been in charge of tweaking a bot written in python and I feel that it is time to convert it over to C++ if the thing is to keep up with the demands it is needed for. I searched google.com and I found a couple things to turn python into C++. Right now I am working on converting a sample python program to a C++ sample program and when I goto compile it, I get errors... Here is the Original Sample Code And after some trial and error, this is where I am at: // this is a test #include <iostream.h> int x = -1; while (x) // loop until 0 spam { cout << "\nHow much spam?"; cin >> x ; if (x) { cout << "We have:" << endl; for (i=0; i<x; i++) { cout << "spam" << " "; if (i == x-2) // (don't forget the beans!) { cout << "baked beans and" << " "; } } } else { cout << "Enjoy!" << endl; } } // all done! Now I am getting the error 'Declaration terminated incorrectly' in this line: while (x) // loop until 0 spam and everything I have seen using goole.com tells me it is correct. Can somebody shed some light on the subject for me please? |
|
#2
|
|||
|
|||
|
Is your code inside a function, like main() or something?
|
|
#3
|
|||
|
|||
|
No, the code I have in the orange/red is exactly how I have it.
|
|
#4
|
|||
|
|||
|
OK, you need a main() function somewhere, something along the following lines:
Code:
#include <iostream.h>
int main()
{
int x = -1;
while (x) {
cout << "\nHow much spam?"; cin >> x ;
if (x) {
cout << "We have:" << endl;
for (int i=0; i<x; i++) {
cout << "spam" << " ";
if (i == x-2) {
cout << "baked beans and" << " ";
}
}
} else {
cout << "Enjoy!" << endl;
}
}
}
|
|
#5
|
|||
|
|||
|
Ahhhh...
That is what I was doing wrong ![]() I tried to put do this before: int main() int x = 1; Thanks for your help As far as trying to learn, i am trying all sorts of tutorials on the internet and such... One of these days I will have to buy a book on C++ |
|
#6
|
|||
|
|||
|
You can download a free copy of Bruce Eckel's Thinking In C++ here:
http://www.mindview.net/Books/TICPP...ingInCPP2e.html but I believe it expects you to have at least a little programming experience at the start so you may need to work through a few tutorials first. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > While Loop Error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|