LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2004, 12:20 PM   #1
tekmorph
Member
 
Registered: Aug 2004
Location: Ohio
Distribution: Mandrake 10.0
Posts: 68

Rep: Reputation: 15
switch statements calling a function


Hello I am new to c++ so please take it easy on me. What I am trying to do is nothing awesome, only call a function that multiplies 2 numbers and outputs a third. This function is called ....aaah I'm sure you know.... here is the code..I get the error
switch.cpp:4: error: too few arguments to function `int doit(int, int, int)'
switch.cpp:29: error: at this point in file
I thought I had enough arguments, I actually thought functions do not even need arguments, that they would just be declared void?
=========================================================
#include <iostream>
using namespace std;
int doit(int x, int y,int z) ////declaring my function doit
{ cout << "Give me a number\n"; ////asking for an int
cin >> x;
cout << "Give me another number\n"; //// asking for the second
cin >> y;
z= x*y; ////setting z to the return value
return (z); //// will this return z for the
//// function?
}
int main()
{
int a; //// the case switch constant
cout << "What would you like to do?\n";
cout << "1:Multiply two numbers\n";
cout << "2:Nothing?\n";
cin >> a; ////case value
switch (a)
{
case 1:
int doit(int x, int y, int z); ////call to doit()
break;

case 2:
cout << "Cya\n";
break;
}
int b= doit(); ////I think this is where I messed
cout <<"\n"<<b<<"\n"; ///it up

return 0;
=======================================================
thanks in advance.......flame away

Last edited by tekmorph; 10-19-2004 at 12:22 PM.
 
Old 10-19-2004, 02:03 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Why passing argument to doit() function as it does not need it ?

Code:
#include <iostream>
using namespace std;
int doit()
{
    int x,y,z;
    cout << "Give me a number\n"; 
    cin >> x;
    cout << "Give me another number\n";
    cin >> y;
    z= x*y; 
    return (z); 
}

int main()
{
    int a, b;
    cout << "What would you like to do?\n";
    cout << "1:Multiply two numbers\n";
    cout << "2:Nothing?\n";
    cin >> a;
    switch (a) {
        case 1:
            b = doit();
            cout <<"\n"<<b<<"\n";
            break;

        case 2:
            cout << "Cya\n";
            break;
    }
    return 0; 
}
 
Old 10-19-2004, 05:53 PM   #3
tekmorph
Member
 
Registered: Aug 2004
Location: Ohio
Distribution: Mandrake 10.0
Posts: 68

Original Poster
Rep: Reputation: 15
Very cool thank you for taking the time to look at that for me, as for your question I am not sure as to why I passed an argument to the function. I see it works perfect without. I am new and learning, but thank you very much for your help.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Function pointers, calling, and templates The_Nerd Programming 2 10-09-2005 07:08 PM
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 03:15 PM
C Loops and switch statements ripwheels8 Programming 4 11-13-2004 04:47 PM
switch statements and input protection (in c) veritas Programming 2 09-27-2004 07:43 PM
Calling my function through MACROS in OpenOfficeWriter mcp_achindra Linux - Software 0 07-05-2004 06:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration