C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 10th, 2004, 05:30 PM
misora misora is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 misora User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking Function help

Hi.
I'm a newbie when it comes to programming...I'm trying to write my first program that contains functions that I write.
I really need some help. I'm getting the error "syntax error before `)' token" every where I try to call a function...I'm not even sure
if how I'm writing the functions is correct. Any help is much appreciated.

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

float calc_peso(float);
float calc_yen(float);
float calc_euro(float);
int get_choice(int);

int main()
{
int amount, i;
int selection;
char answer = 'y';
float result;

selection = get_choice(int);
for( ;selection != 4; )
{
if(selection == 1)

result = calc_peso(float);

else
if(selection == 2)

result = calc_yen(float);

else
selection = calc_euro(float);

}
system("PAUSE");
}

int get_choice();
{
int choice;
cout<<"Please make a selection to obtain conversion:\n Enter 1 to convert to"
<<" peso.\n Enter 2 to convert to Yen.\n Enter 3 to convert to Euro.\n"
"Enter 4 to quit."<<endl;

cin >>selection;
return choice;
}
float calc_peso(float x)
{
float result;
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = x * 0.08822;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}
float calc_yen(float x)
{
float result;
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = x * 105.26;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}

Reply With Quote
  #2  
Old December 10th, 2004, 08:21 PM
marmo marmo is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 37 marmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 20 sec
Reputation Power: 4
I have pointed out the errors in your code.

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

float calc_peso(float);
float calc_yen(float);
float calc_euro(float);
int get_choice(int);

int main()
{
int amount, i;
int selection;
char answer = 'y';
float result;

// Error1: You are passing a built in type as the argument for the function. You need to pass in a variable such as,
selection = get_choice( amount );
or
selection = get_choice( 10 );

selection = get_choice(int);

// I have no clue what arguments you plan on passing to the calc_peso, calc_yen, calc_euro functions.

for( ;selection != 4; )
{
if(selection == 1)

// Same as Error1
result = calc_peso(float);

else
if(selection == 2)

// Same as Error1
result = calc_yen(float);

else
// Same as Error1
selection = calc_euro(float);

}
system("PAUSE");
}

// Error2: When you declared this function up top it had an int parameter what happened to it here?

int get_choice();
{
int choice;
cout<<"Please make a selection to obtain conversion:\n Enter 1 to convert to"
<<" peso.\n Enter 2 to convert to Yen.\n Enter 3 to convert to Euro.\n"
"Enter 4 to quit."<<endl;

cin >>selection;
return choice;
}

float calc_peso(float x)
{
float result;
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = x * 0.08822;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}

float calc_yen(float x)
{
float result;
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = x * 105.26;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}[/QUOTE] You are missing a function definition for calc_euro. Also your function definitions have been placed inside the main function. Your function declarations go at the top and the function definitions go below. However placing them inside main will not generate an error this is poor style. You should try googlin for some beginner tutorials on c++.

Reply With Quote
  #3  
Old December 11th, 2004, 12:19 AM
misora misora is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 misora User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks so much for the input... I have updated my code a little. Maybe now it makes
a little more sence or maybe not..hehe. Well at least it runs now. The only thing is that it does not
drop out of the loop when its suppose to. I will do some tutorials.

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
float calc_peso(float);
float calc_yen(float);
float calc_euro(float);
int get_choice();

int main()
{
//set up variables
int amount, i;
int selection;
float result;
float p = 0.08822, y = 105.26, e = 1.321;

selection = get_choice();
//select what to convert us dollars to
for( ;selection != 4; )
{
if(selection == 1)

result = calc_peso(p);

else
if(selection == 2)

result = calc_yen(y);

else
selection = calc_euro(e);

}
system("PAUSE");

}//end of main

int get_choice()
{
int choice;
cout <<"Please make a selection to obtain conversion:\n Enter 1 to convert to"
<<" peso.\n Enter 2 to convert to Yen.\n Enter 3 to convert to Euro.\n"
"Enter 4 to quit."<<endl;
cin >>choice;
return choice;
}
float calc_peso(float p)
{
float result, amount;
int i;
char choice;


for(;choice = 'y'
{
cout <<"Please enter a US dollar amount to convert : "<<endl;
cin >>amount;
result = amount * p;
cout <<result<<endl;
cout <<"Would you like to enter another? y or n"<<endl;
cin >> choice;
}

return result;
}
float calc_yen(float y)
{
float result, amount;
int i;
char answer = 'y';
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = amount * y;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}
float calc_euro(float e)
{
float result, amount;
int i;
char answer = 'y';
for(i = 0; answer == 'y'; ++i)
{
cout <<"Please enter a US dollar amout to convert : "<<endl;
cin >>amount;
result = amount * e;
cout <<result<<endl;
cout <<"Would you like to enter another?"<<endl;
cin >>answer;
}

return result;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Function help


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 4 hosted by Hostway