| | |
Need help!
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
1
#4 Oct 23rd, 2009
C++ Syntax (Toggle Plain Text)
// 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; }
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.
![]() |
Other Threads in the C++ Forum
Views: 164 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop directshow display dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






