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 January 14th, 2005, 05:43 AM
piepes piepes is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 7 piepes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face function calling not working :S

i have a better version of this code at home but i am working at college to try and get my program to call the functions listed when needed.

the assignment is nearly finnished as it is quite easy but..... when i call function void exit(); for example, it doesn't create an error, simply ignores it and carry's on as the program would anyway! :S

could someone take a look and see if they can help me out, jus dont change it too much! :P

i have a delay aswell that needs adding but i have all of that typed up at home!

cheers!

Code:
#include <iostream.h>
// include headers
#include <stdlib.h>
#include <time.h>
// include stdlib header to enable CLS function
char password[5], name[50];
// declare variables of type char
int input, score, ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans9, ans10, per;
// declare program variables - int
void main();
void table();
void Question1();
void Question2();
void Question3();
void Question4();
void Question5();
void Question6();
void Question7();
void Question8();
void Question9();
void Question10();
void results();
void exit();
void main()
// start of program
{
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Password Protected Program!\n";
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 cout<<"Please enter your Name: ";
 cin>>name;
 // prompt for Name to be enterd
 
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Password Protected Program!\n";
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 cout<<"Welcome ";
 cout<<name;
 cout<<": \n";
 cout<<"\nPlease enter the program Password (5 characters): ";
 cin>>password;
 // prompt for password
 if (password[0] == 'm' && password[1] == 'o' && password [2] == 'n' && password[3] == 'k' && password[4] == 'e' && password [5] == 'y')
 
 // check password is correct
 {
  system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n"; // simple 'who logged in' tag
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 // tells user who is logged in
 system("CLS");
 // Clears and starts program
 //////////////////////////////////////////////////////
 // MENU BAR HERE /////////////////////////////////////
void table();
{
 cout<<"\nPlease Select an option from the menu below:";
 cout<<"\n\n1. Start the Test.\n2. Exit";
 cout<<"\n\nPlease enter the number you want to select: ";
 cin>>input;
 if ( input == 1 )
 {
  void Question1();  // call question one to start
 }
 else
 {
  void exit();  // call for function 'exit' to start
 }
}
  
 //////////////////////////////////////////////////////
 // INTERNAL PROGRAM STARTS HERE //////////////////////

 
void Question1();   // test questions start here! run question
 {
 cout<<"\nQuestion 1:\nLive is to evil as 98760 is to: \n";
 cout<<"\n1:98067\n2:06789\n3:08967\n4:98760\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans1;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";   
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if ( ans1 == 2 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 
 }

void Question2(); // question 2
 {
 cout<<"\nQuestion 2:\nWhat comes next in the series: 120, 118, 115, 111, 106...: \n";
 cout<<"\n1: 105\n2: 85\n3: 100\n4: 98\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans2;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  ans2 == 3 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }
void Question3(); // question 3
 {
 cout<<"\nQuestion 3:\nHand is to Glove as Head is to: \n";
 cout<<"\n1: Hat\n2: Hair\n3: Earing\n4: Neck\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans3;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  ans3 == 1 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }
 
void Question4(); // question 4
 {
 cout<<"\nQuestion 4:\nIf you rearrange the Numbers NAMYERG you would have the name of an: \n";
 cout<<"\n1: City\n2: Ocean\n3: State\n4: Country\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans4;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  ans4 == 4 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }

void Question5(); // question 5
 {
 cout<<"\nQuestion 5:\nAnn is taller than Jill, and Kelly is shorter than Ann.\nWhich of the following statements would be most accurate?: \n";
 cout<<"\n1: Kelly is taller than Jill\n2: Kelly is shorter than Jill\n3: It's impossible to tell\n4: Kelly is as tall as Jill\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans5;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans5) == 3 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }

void Question6(); // question 6
 {
 cout<<"\nQuestion 6:\nIf some Wicks are Slicks, and some Slicks are Snicks.\nThen some Wicks are definitely Snicks. The statement is: \n";
 cout<<"\n1: True\n2: False\n3: Neither\n4: Impossible to tell\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans6;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans6) == 1 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }

void Question7(); // question 7
 {
 cout<<"\nQuestion 7:\nWhat number is one half of one quarter of one tenth of 800?: \n";
 cout<<"\n1: 2\n2: 5\n3: 8\n4: 10\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans7;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans7) == 4 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }

void Question8(); // question 8
 {
 cout<<"\nQuestion 8:\nTen people can paint 60 houses in 120 days\nSo five people can paint 30 houses in: \n";
 cout<<"\n1: 15 days\n2: 30 days\n3: 60 days\n4: 120 days\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans8;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans8) == 4 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }
 
void Question9(); // question 9
 {
 cout<<"\nQuestion 9:\nA car traveled 28 miles in 30 minutes. How many miles per hour was it traveling?\n";
 cout<<"\n1: 28\n2: 36\n3: 56\n4: 58\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans9;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans9) == 3 )
 {
  cout<<"!! Correct, next Question: !!\n\n";
  score++;
 }
 else
 {
  cout<<"!! Incorrect, next Question: !!\n\n";
  
 }
 
 }

void Question10(); // question 10
 {
 cout<<"\nQuestion 10:\nWhat is the chemical symbol for water?: \n";
 cout<<"\n1: W\n2: H2O\n3: O2\n4: Liq\n\nPlease enter the Number of the required Answer, only one is correct: ";
 cin>>ans10;
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Loged In as: ";
 cout<<name;
 cout<<"\n+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 if (  (ans10) == 2 )
 {
  cout<<"Results:\n\n";
  score++;
 }
 else
 {
  cout<<"Results:\n\n";
  
 }
 
 }
void results(); // start of function 'results' to display how used did in the test
{
 system("CLS");
 cout<<"Congratulations!\n\nYou have Completed the IQ test!\n\n";
 cout<<"Your results are: ";
 cout<<score;  // output the users score
 cout<<" Out Of 10!\n\n";  // out of 10
 per=score*10;  // calculates the users percentage
 cout<<"You got ";
 cout<<per;
 cout<<" Percent!\n\n"; // tells the user what % they acheived
 if (score < 6)		 // pass or fail?
 {
  cout<<"!! Sorry, you Falied !!\n\nBetter Luck Next Time!\n\n";  // failed message
 }
 else
 {
  cout<<"Well done!\n\nYou Passed!\n\n";	// passed message
 }
}
 // END OF INTERNAL PROGRAM ///////////////////////////
 //////////////////////////////////////////////////////
}
 
 
 else
 {
 system("CLS");
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n";
 cout<<"Password Protected Program!\n";
 cout<<"+*+*+*+*+*+*+*+*+*+*+*+*+*+\n\n";
 cout<<"\n!ERROR!\n\n";
 cout<<"Incorrect password - please restart program and try again!\n\n";
 // tells user they have enterd an incorrect password
 system("CLS");
 void main();  // calls main function to restart
 }

void exit();   // small function to be called when an exit is wanted
{
 system("CLS");
 cout<<"Thankyou, Goodbye!\n\n";
}
};
// end of program

Reply With Quote
  #2  
Old January 14th, 2005, 12:30 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: 5
When you make function calls you leave out the return type and parameter types.
So when you call the exit function it should look like this:
exit();
not
void exit();

Also your function declarations are placed above main() and your function definitions should be placed below main(), not inside main().

Reply With Quote
  #3  
Old January 21st, 2005, 08:56 PM
Link-Jun Link-Jun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 Link-Jun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 58 sec
Reputation Power: 0
Quote:
Originally Posted by marmo
When you make function calls you leave out the return type and parameter types.
So when you call the exit function it should look like this:
exit();
not
void exit();

Also your function declarations are placed above main() and your function definitions should be placed below main(), not inside main().


Is putting func declarations above main() and definitions below a matter of programming style? Or could you actually declare and define function all within main()?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > function calling not working :S


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 6 hosted by Hostway
Stay green...Green IT