C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 22nd, 2003, 12:46 PM
Longhair Longhair is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 14 Longhair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old June 22nd, 2003, 01:42 PM
BigBadBob BigBadBob is offline
status unknown
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 262 BigBadBob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Is your code inside a function, like main() or something?

Reply With Quote
  #3  
Old June 22nd, 2003, 02:41 PM
Longhair Longhair is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 14 Longhair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No, the code I have in the orange/red is exactly how I have it.

Reply With Quote
  #4  
Old June 22nd, 2003, 03:08 PM
BigBadBob BigBadBob is offline
status unknown
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 262 BigBadBob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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; 
        } 
    } 
}
This should be covered very early on in any beginners book, see if you can get your hands on one.

Reply With Quote
  #5  
Old June 22nd, 2003, 03:15 PM
Longhair Longhair is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 14 Longhair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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++

Reply With Quote
  #6  
Old June 22nd, 2003, 03:50 PM
BigBadBob BigBadBob is offline
status unknown
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 262 BigBadBob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > While Loop Error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway