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 February 17th, 2005, 10:50 AM
leftd90 leftd90 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 leftd90 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 46 sec
Reputation Power: 0
I dont know what Im doing wrong.

This is my code and it compiles but i cant get numbers to be stored in. I get the menu to come up and i try to make a selection but than the menu just loops over again without it asking me to enter in a number for at_bats or walk ect..... Does anybody know how i can get it to do what i want. Thanks

#include <iostream>
using namespace std;
int displayMenu(void);
int main(void)
{
int menuChoice = 0;
menuChoice = displayMenu();
while(menuChoice!=6)
{
if (menuChoice);
menuChoice = displayMenu();
}
return 0;
}
float get_option ()
{
float a, b, c;
cout<<"Give me a number"<<endl;
cin>>a;
return (a);
}
int displayMenu(void)
{
float option, hits, at_bats, walks;
int retValue = 0;
cout<<"Please select a number from the list below:"<<endl;
cout<<"1. Enter total number of at bats"<<endl;
cout<<"2. Enter total number of hits"<<endl;
cout<<"3. Enter total number of walks"<<endl;
cout<<"4. Display batting average"<<endl;
cout<<"5. Display on base percentage"<<endl;
cout<<"6. Exit"<<endl;
cin>>retValue;
return(retValue);
option=get_option ();
int menuChoice (int choice);
{
float option, hits, walks, at_bats;
if (option==1.0)
{
cout<<"How many at bats";
cin>>at_bats;
}
else if (option == 2.0)
{
cout<<"How many hits";
cin>>hits;
}
else if (option == 3.0)
{
cout<<"How many walks";
cin>>walks;
}
else if (option == 4.0)
{
cout<<"Your batting average is"<<hits/at_bats<<endl;
}
else if (option == 5.0)
{
cout<<"Your on base percentage is"<<(hits+walks)/at_bats<<endl;
}
else
{
cout<<"Goodbye"<<endl;
}
}
}

Reply With Quote
  #2  
Old February 17th, 2005, 12:08 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey leftd90! Your code wasn't all wrong...just missplaced. I rewrote it for you below. Try this to see how it goes.

Good Luck

Anibal.


Code:
 
#include <iostream> 
using namespace std;
int displayMenu(void);
void menuChoice(int);
 
//global variables...(could be a global struct and pass a pointer also!)
float hits, walks, at_bats;
 
int main(void)
{
	int menu = 0;
	int option;
	menu = displayMenu();
	while((menu != 6) && (menu > 0) && (menu < 7))
	{
		menuChoice(menu);
		menu = displayMenu();
	}
	cout<<"Goodbye"<<endl;

	return 0;
}
//<-----------------end of main ------------->
 
 
//<-----------------declaration of functions------------->
int displayMenu(void)
{
	int retValue = 0;
	cout<<"Please select a number from the list below:"<<endl;
	cout<<"1. Enter total number of at bats"<<endl;
	cout<<"2. Enter total number of hits"<<endl;
	cout<<"3. Enter total number of walks"<<endl;
	cout<<"4. Display batting average"<<endl;
	cout<<"5. Display on base percentage"<<endl;
	cout<<"6. Exit"<<endl;
	cin>>retValue;
	return(retValue);
}
 
 
void menuChoice (int option);
{
	//simply to give the user time to see the statistics
	int waitkey
 
	switch(option)
	{
		case 1: cout<<"How many at bats";
				 cin>>at_bats;
				 break;
 
		case 2: cout<<"How many hits";
				 cin>>hits;
				 break;
 
		case 3: cout<<"How many walks";
				 cin>>walks;
				 break;
 
		case 4: cout<<"Your batting average is"<<hits/at_bats<<endl;
				 cout<<"Press a Key";
				 cin>>waitkey;
				 break;
 
		case 5: cout<<"Your on base percentage is"<<(hits+walks)/at_bats<<endl;
				 cout<<"Press a Key";
				 cin>>waitkey;
				 break;
 
		default: break;
	}
}

Reply With Quote
  #3  
Old February 17th, 2005, 12:26 PM
leftd90 leftd90 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 leftd90 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 46 sec
Reputation Power: 0
Im getting these errors


assign4.cpp:44: parse error before `{' token
assign4.cpp:51: syntax error before `>>' token
assign4.cpp:55: syntax error before `>>' token
assign4.cpp:59: syntax error before `>>' token
assign4.cpp:62:31: warning: multi-line string literals are deprecated
assign4.cpp:64: syntax error before `<<' token
assign4.cpp:65: syntax error before `>>' token
assign4.cpp:68:31: warning: multi-line string literals are deprecated
assign4.cpp:70: syntax error before `<<' token
assign4.cpp:71: syntax error before `>>' token

Reply With Quote
  #4  
Old February 18th, 2005, 08:17 AM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Talking

Hey! Sorry...I accidently wrote a ; at the end of line 44 ( void menuChoice(int option);)
remove the ; and you shouldn't have any problems

Anibal.

PS: when you find an error, check the line. Generaly is either that line (44) or the line before. I'm happy to help you, but you need to learn how to debug errors on your own!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > I dont know what Im doing wrong.


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