Apr 16, 2009 at 12:47pm UTC
Help me whats wrong with this program.
menufunction.h.h
# include <iostream>
# include <cstdlib>
using namespace std ;
int switchstatement (int) ;
void CoinExchange() ;
void casestatement() ;
void LYD () ;
char MenuInput() ;
assg5.cpp
# include "menufunction.h.h"
char MenuInput()
{
char choice ;
cout <<"\n-------------------------------------------\n"
<<"\n 1. [C}oin Exchange \n"
<<"\n 2. [L]eap Year Determination \n"
<<"\n 3. [P]ostage Calculation \n"
<<"\n 4. Prime [N]umber Generator \n"
<<"\n 5. [Q]uit \n"
<<"\n-------------------------------------------\n"
<<"Your Choice is : " ;
cin >> choice ;
cout <<endl ;
return choice;
}
menufunction.cpp.cc
# include "menufunction.h.h"
int main ()
{
char choice ;
MenuInput() ;
switch (choice)
{
case 1 :
if (choice == '1' || choice == 'C')
CoinExchange() ;
break ;
case 2 :
if (choice == '2' || choice == 'L')
void LYD () ;
break ;
}
return 0 ;
}
void CoinExchange()
{
float Money , fifty ,twenty ,ten , five ,one ;
cout << "Please key in the total amount change (cents) " ;
cin >> Money ;
cout << endl ;
fifty = Money/50 ;
twenty = (Money - fifty*50)/20 ;
ten = (Money - twenty*20-fifty*50)/10 ;
five = (Money - twenty*20-fifty*50-ten*10)/5 ;
one = (Money - twenty*20-fifty*50-ten*10-five*5) ;
cout << fifty ;
cout << twenty ;
cout << ten ;
cout << five ;
cout << one ;
}
void LYD ()
{
int year ;
cout << "Please key in a year " ;
cin >> year ;
if (year % 4 != 0)
{
cout << year
<< "is not a leap year" ;
if (year % 400 == 0 )
cout << year
<< " is a leap year " ;
else if ( year % 100 != 0)
cout << year
<< " is a leap year " ;
else
cout << year
<< " is not a leap year " ;
}
cout << endl ;
}
Apr 16, 2009 at 1:03pm UTC
in the function char MenuInput() the line
<<"\n 1. [C}oin Exchange \n"
should be changed to
<<"\n 1. [C] oin Exchange \n"
only scimmed program i will get a better look later...
Apr 16, 2009 at 1:20pm UTC
That is not an error.
Did you try to compile this?
Apr 16, 2009 at 2:02pm UTC
Hmm but the problem is when i key in the choice into the cmd, it does not process wat i wanted. Is it got to do with the choice part which i don't know what is wrong or where is my mistake... Someone please help me point it out. Thanks
Last edited on Apr 16, 2009 at 2:05pm UTC
Apr 16, 2009 at 11:48pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# include "menufunction.h.h"
char MenuInput(char choice)//you should have "char choice" here
{
cout <<"\n-------------------------------------------\n"
<<"\n 1. [C}oin Exchange \n"
<<"\n 2. [L]eap Year Determination \n"
<<"\n 3. [P]ostage Calculation \n"
<<"\n 4. Prime [N]umber Generator \n"
<<"\n 5. [Q]uit \n"
<<"\n-------------------------------------------\n"
<<"Your Choice is : " ;
cin >> choice ;
cout <<endl ;
return choice;
}
menufunction.cpp.cc
# include "menufunction.h.h"
int main ()
{
char choice ;// and here
choice = MenuInput() ;
switch (choice)
{
case 1 :
if (choice == '1' || choice == 'C' )
CoinExchange() ;
break ;
case 2 :
if (choice == '2' || choice == 'L' )
void LYD () ;
break ;
}
return 0 ;
}
You have to set the choice declared in main to the return value of MenuInput().
Last edited on Apr 16, 2009 at 11:49pm UTC