GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Apr-2009, 21:02
D2rasta D2rasta is offline
New Member
 
Join Date: Apr 2009
Posts: 1
D2rasta is on a distinguished road

Math program (small) compiling and math errors .


Hey guys im trying to learn C++.

This was a simple program i made while reading C++ For dummies
CPP / C++ / C Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;


int BigDog(int KibblesCount) {
     int NumCount;
    cout << "How many kibbles should we feed the doggie?" << endl;
    cin >> KibblesCount;
     cout << "I'm a lucky dog" << endl;
     cout << "I have " << KibblesCount<< " doggie treats" << endl;
          cout << "RUFF RUFF RUFF" << endl;
          KibblesCount = NumCount;
          while(NumCount > 0) {
                cout << "Num num num num thanks!" << endl;
                NumCount--;
                }
               cout << "Ruh Roh! I Are All Out!" << endl;
}
    
int main(int argc, char *argv[])
{
    BigDog(KibblesCount);
    system("PAUSE");
            return 0;
}

First it said, KibblesCount is undeclared. So i put
Code:
Int KibblesCount
at the top.

Then, when i put an integer to basically "Feed the dog" it spammed it then exited.


What this prog does
--------------------
You experts know but for the lazy, im trying to make it so when you enter an integer, it will say Num Num Num that many times.

Thanks in advance
Last edited by LuciWiz : 30-Apr-2009 at 02:10. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 29-Apr-2009, 22:18
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 800
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Math program (small) compiling and math errors .


What is spammed? you mean endless loop?
You have:
while(NumCount > 0)

What do you think NumCount's value is?

You can see by printing it. Just add to the exsiting print:
cout << "Num num num num thanks! NumCount=" << NumCount << endl;

Try that and see it you understand better what is wrong.

also
windows.h is not being used in your program , don't include it.

The only thing you need cstdlib.h for is the system() function in.
system("PAUSE");

PAUSE is window specific. You can pause C++ style instead:
cin.get(); // waits until return is pressed

then you can loose #include <cstdlib.h> too.
(you'll also learn something else about user input , you might need two cin.get(); 's. Why? (more will be revealed): )

So you'll just have:
#include <iostream>
using namespace std;
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:43.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.