Need help!

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 2
Reputation: Ace1.0.1. is an unknown quantity at this point 
Solved Threads: 0
Ace1.0.1. Ace1.0.1. is offline Offline
Newbie Poster

Need help!

 
0
  #1
Oct 23rd, 2009
Just picked up a beginners book on C++
so i'm pretty new at this.
trying to write a program to test what i have learned so far, but it's not coming out as i had hoped
so i'm hoping someone can help me out
constructive criticism welcomed

Here it is:
// Test #02 new version
// Title : The Question ?
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int nAnswer;
int nAnswer2;
void displayExplanation()
{
//code starts here
cout << "The name of the game is\n"
<< "The Question\n"
<< "The Object of the game is\n"
<< "To answer all\n"
<< "The\n"
<< "Questions\n"
<< "(Correctly that is)\n"
<< " Press 1 for yes or 2 for no\n"
<< endl;
return;
}
void checker1(void)
{
if (nAnswer == 1)
{

cout << "That is correct"
<< endl;
}
else
{
cout << "Sorry try again :["
<< endl;
}
return;
}
void checker2(void)
{
if (nAnswer2 == 2)
{
cout << "That is correct"
<< endl;
}
else
{
cout << "Sorry try again :["
<< endl;
}
return;
}
int main(int nNumberofArgs, char* pszArgs[])
{

displayExplanation();
//
//
cout << "Question #01\n"
<< "George Washington was the first President\n"
<< endl;
cin >> nAnswer;
void checker1();



cout << "Question #02\n"
<< "The square root of 144 is 13"
<< endl;
cin >> nAnswer2;
void checker2();

system("PAUSE");
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 251
Reputation: sfuo is on a distinguished road 
Solved Threads: 29
sfuo's Avatar
sfuo sfuo is offline Offline
Posting Whiz in Training
 
1
  #2
Oct 23rd, 2009
In the future use the code tags to make it easier for us to read.

I compiled this and it ran fine. What did you need help with?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 19
Reputation: Kontained is an unknown quantity at this point 
Solved Threads: 5
Kontained Kontained is offline Offline
Newbie Poster
 
0
  #3
Oct 23rd, 2009
Edit...
Sorry, misunderstood the question.
Last edited by Kontained; Oct 23rd, 2009 at 12:18 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
1
  #4
Oct 23rd, 2009
  1. // Test #02 new version
  2. // Title : The Question ?
  3. //
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. int nAnswer;
  10. int nAnswer2;
  11. void displayExplanation()
  12. {
  13. //code starts here
  14. cout << "The name of the game is\n"
  15. << "The Question\n"
  16. << "The Object of the game is\n"
  17. << "To answer all\n"
  18. << "The\n"
  19. << "Questions\n"
  20. << "(Correctly that is)\n"
  21. << " Press 1 for yes or 2 for no\n"
  22. << endl;
  23. return;
  24. }
  25. void checker1(void)
  26. {
  27. if (nAnswer == 1)
  28. {
  29.  
  30. cout << "That is correct"
  31. << endl;
  32. }
  33. else
  34. {
  35. cout << "Sorry try again :["
  36. << endl;
  37. }
  38. return;
  39. }
  40. void checker2(void)
  41. {
  42. if (nAnswer2 == 2)
  43. {
  44. cout << "That is correct"
  45. << endl;
  46. }
  47. else
  48. {
  49. cout << "Sorry try again :["
  50. << endl;
  51. }
  52. return;
  53. }
  54. int main(int nNumberofArgs, char* pszArgs[])
  55. {
  56.  
  57. displayExplanation();
  58. //
  59. //
  60. cout << "Question #01\n"
  61. << "George Washington was the first President\n"
  62. << endl;
  63. cin >> nAnswer;
  64. void checker1();
  65.  
  66.  
  67.  
  68. cout << "Question #02\n"
  69. << "The square root of 144 is 13"
  70. << endl;
  71. cin >> nAnswer2;
  72. void checker2();
  73.  
  74. system("PAUSE");
  75. return 0;
  76. }


Yes, use code tags. Look at lines 64 and 72. Function calls don't have the function return types. Functions and function declarations do, but not function calls. Get rid of the word "void" in those lines.

And yes, describe in detail what the problem is. "It's not coming out as I had hoped" is too vague.
Last edited by VernonDozier; Oct 23rd, 2009 at 12:43 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: Ace1.0.1. is an unknown quantity at this point 
Solved Threads: 0
Ace1.0.1. Ace1.0.1. is offline Offline
Newbie Poster
 
0
  #5
Oct 23rd, 2009
Thank you very much VernonDozier, that fixed the problem
and i'll try be less vague and more descriptive next time.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 164 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC