Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Won't Compile? C++ program

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Blazin
Grandmaster Cheater
Reputation: 0

Joined: 17 Sep 2006
Posts: 770
Location: Somewhere over the rainbow.

PostPosted: Sun Mar 30, 2008 5:22 pm    Post subject: Won't Compile? C++ program Reply with quote

I'm trying to compile another program, and when i do it gives me the error that there is an expected '}' at the end of input. However, everything that should be is there. I'm trying to write this program to practice C++, I'm just learning it. Why is it giving me that error?

Code:
// This is a program to find out how many calories a certain
// person are
// egg = 100 calories
// Pancakes = 200 calories
// chocolate = 300 calories
// apple = 50 clories
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
    string nNamePerson;
    cout << "What is the name of the person who's calorie intake you are"
    << " calculating?\nDon't enter negative values.";
    cin >> nNamePerson;
    int nLoop1 = 1;
    while (nLoop1-- > 0)
    {
    int nEgg;
    cout << "\nHow many eggs did they consume?";
    cin >> nEgg;
    if (nEgg < 0)
    {
             cout << "Error-Cannot enter negative values.";
             continue;
             }
    int nPancakes;
    cout << "\nHow many pancakes did they consume?";
    cin >> nPancakes;
    int nChocolate;
    cout << "\nHow many chocolates did they consume?";
    cin >> nChocolate;
    int nApple;
    cout << "\nHow many apples did they consume?";
    cin >> nApple;
    int nEggCal;
    nEggCal = nEgg * 100;
    int nPancakeCal;
    nPancakeCal = nPancakes * 200;
    int nChocCal;
    nChocCal = nChocolate * 300;
    int nAppleCal;
    nAppleCal = nApple * 50;
    int nCalTotal;
    nCalTotal = nEggCal + nPancakeCal + nChocCal + nAppleCal;
    cout << "\nThe total calories " << nNamePerson << " consumed is: "
    << nCalTotal;
system("PAUSE");
return 0;
}
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 30, 2008 5:25 pm    Post subject: Reply with quote

You didnt close your While Loop....
_________________
Back to top
View user's profile Send private message
Blazin
Grandmaster Cheater
Reputation: 0

Joined: 17 Sep 2006
Posts: 770
Location: Somewhere over the rainbow.

PostPosted: Sun Mar 30, 2008 5:26 pm    Post subject: Reply with quote

lurc wrote:
You didnt close your While Loop....


When i try to close it, it tells me I didn't declare what nEgg was, and I obviously did. Any other solutions?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 30, 2008 5:29 pm    Post subject: Reply with quote

Put int nEgg outside the loop, and close it.

Edit: Actually, i'd just declare all variables outside the loop.

_________________
Back to top
View user's profile Send private message
Blazin
Grandmaster Cheater
Reputation: 0

Joined: 17 Sep 2006
Posts: 770
Location: Somewhere over the rainbow.

PostPosted: Sun Mar 30, 2008 5:41 pm    Post subject: Reply with quote

lurc wrote:
Put int nEgg outside the loop, and close it.

Edit: Actually, i'd just declare all variables outside the loop.


Thanks, it compiles now, but where i put the continue function, it doesn't start at the top of the loop, it just continues. Why is that?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 30, 2008 6:03 pm    Post subject: Reply with quote

replace the check with a do while loop, like this:

Code:
do
{
    cout << "\nHow many eggs did they consume\? (No Negative Numbers)";
    cin >> nEgg;
}
while ( nEgg < 0 );

_________________
Back to top
View user's profile Send private message
Blazin
Grandmaster Cheater
Reputation: 0

Joined: 17 Sep 2006
Posts: 770
Location: Somewhere over the rainbow.

PostPosted: Sun Mar 30, 2008 6:10 pm    Post subject: Reply with quote

lurc wrote:
replace the check with a do while loop, like this:

Code:
do
{
    cout << "\nHow many eggs did they consume\? (No Negative Numbers)";
    cin >> nEgg;
}
while ( nEgg < 0 );


Thanks, it worked. I haven't learned about the do loop yet, but I'm sure I will. Thanks. +Rep.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Mar 30, 2008 6:33 pm    Post subject: Reply with quote

do-while loop is basically the same as the while loop, the only difference is that the do while loop runs through once before checking the argument that was stated in the while( )
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites