Problems calling this function

This is a discussion on Problems calling this function within the C++ Programming forums, part of the General Programming Boards category; Ive been trying to learn C++ for over two weeks now hoping to get into win32 api's soon but simple ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    13

    Problems calling this function

    Ive been trying to learn C++ for over two weeks now hoping to get into win32 api's soon but simple ........ is stumping me. I know all about data types and basic stuff but I just dont seem to get it? idk my code looks alright i though I didnt organize it here thats not what im worryin about I was wondering is this the best way to write this function?

    Code:
    // xwxw.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    void getnumber();
    
    using namespace std;
    int number;
    
    int main()
    {
    
    	cout<<"Give me the number:";
    	cin>> number;
    getnumber();
    	cin.get();
    cin.ignore();
    
    
    }
    
    void getnumber()
    {
    
    	int x = 5;
    int b = number;
    	while (x < b) {
    		cout<< x<<endl;
    		x++;
    	}
    	cin.get();
    	cin.ignore();
    }

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    9
    I would write it like this...
    Code:
    #include <iostream>
    
    using namespace std;
    
    void GetNumber(int number);
    
    int main(){
        
        int number;
        cout <<"Type a number: ";
        cin >> number;
        GetNumber(number);
        
        return 0;
    }
    void GetNumber(int number){
                  for(int x=5;x<number;x++){
                                        cout << x << endl;
                                        }
    }
    Using a for loop and not declaring global variables...

    is that what you were looking for? :s...
    Last edited by Hirosh; 09-17-2009 at 04:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21