Testing Application

This is a discussion on Testing Application within the C++ Programming forums, part of the General Programming Boards category; I need help with trying to find out how to make a game with C++. I don't want any fancy ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    13

    Testing Application

    I need help with trying to find out how to make a game with C++. I don't want any fancy graphics ........ or anything, just something like this:

    "State Comma Rule 7: *User puts in whatever they think Comma Rule 7 is*"

    If User gets it right:

    "Correct!"

    If User gets it wrong:

    "Incorrect. The answer is *whatever the actual answer is*"

    Then it keeps going with more questions.

    I am learning C++ right now, but can't figure out how to write this. Any help, please?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Well, if you can't do that, you need to tell us what you do know and how far you got.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Well, I picked up the book "C++ for Dummies" and have gotten to page 88. I have just gotten into it last week. The main reason I want to know how to do this is to help me learn and remember some English related material. I have almost all the basics covered. I know about functions, integers, arguments, syntax and semantics. But next semester, in school, I am taking a class in C++. So right now I am just doing it for the fun of it. So, can you help me in the coding for this idea?

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Output text to screen.
    Read input from user.
    Check the input from user.
    If user answers correctly,
    print "Correct!"
    Otherwise,
    print "Incorrect..."

    Basic structure. Read a little on input/output and you should find it's not so hard.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Cool, thanks Elysia.

    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
    	int question;
    	cout <<"What is Comma Rule One? ";
    	cin >> question;
    
    	int answer;
    	answer = Use the comma to separate items in a series;
    
    	bool b;
    	b = question == answer;
    
    	cout << "Correct!";
    	system("PAUSE");
    	return 0;
    }
    Am I on the right track? I know I didn't put in the operations to make it keep going to the next question or the operations in the event of the wrong answer.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Quote Originally Posted by RazorBlade View Post
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
    	int question;
    	cout <<"What is Comma Rule One? ";
    	cin >> question;
    
    	int answer;
    	answer = Use the comma to separate items in a series;
    
    	bool b;
    	b = question == answer;
    
    	cout << "Correct!";
    	system("PAUSE");
    	return 0;
    }
    Am I on the right track? I know I didn't put in the operations to make it keep going to the next question or the operations in the event of the wrong answer.
    The first part, highlighted with red is right. Though cin takes input so it might be better to rename question to answer.
    To see if the answer is right, you need IF.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Quote Originally Posted by Elysia View Post
    The first part, highlighted with red is right. Though cin takes input so it might be better to rename question to answer.
    To see if the answer is right, you need IF.
    No it's not. He's trying to read a string in as an int.

    @RazorBlade
    To store a string -- a sequence of characters -- you need to use a string object. To do this, #include <string> at the top. String variables are declare like this:
    Code:
    string answer;
    You also need quotes around the string literal you are currently assigning to answer.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Is the answer an int or a string? I don't know if I actually thought about that. If the answer is an int, then it's right.
    Strings are tricky things to check since they can vary in meaning so much for the same thing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Quote Originally Posted by Elysia View Post
    Is the answer an int or a string? I don't know if I actually thought about that. If the answer is an int, then it's right.
    Strings are tricky things to check since they can vary in meaning so much for the same thing.
    He's trying to make an open response quiz game. As per the first post. That requires all responses to be strings.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Okay, I was kind of second guessing when I posted my code because of the whole int thing. I haven't gotten to the part in the book yet where it deals with string. But I am confused on what I should do. Should I take Elysia's advice and change all of my "question"'s to "answer"'s? Or should I what King is saying and put the #include <string>?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Yes, change question to answer, because you're actually reading an answer into that variable, are you not? Then answer would be a more appropriate name for it.
    Since you're going to use std::string (declare answer as std::string), then you're going to have to include <string> because that's where it's defined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Quote Originally Posted by RazorBlade View Post
    Okay, I was kind of second guessing when I posted my code because of the whole int thing. I haven't gotten to the part in the book yet where it deals with string. But I am confused on what I should do. Should I take Elysia's advice and change all of my "question"'s to "answer"'s? Or should I what King is saying and put the #include <string>?
    Both. And also, what Elysia said about if.

    Except that you can't have two variables called answer in the same scope. Elysia's just pointing out that question is not a good name for the variable that stores the users answer to the question.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
    	int answer;
    	cout <<"Use the comma to separate items in a series.";
    	cin >> answer;
    
    	string question;
    	question = "What is Comma Rule One? ;
    	if (question == answer)
    	{
    		cout << "Correct!";
    	}
    	else
    	{
    		cout << "Incorrect!  Comma Rule One is use the comma to separate items in a series.";
    	}
    
    	cout << "Correct!";
    	system("PAUSE");
    	return 0;
    }
    Like this?

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    That makes no sense. Think about what you're doing for a moment.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,468
    it even will not compile
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cleanup of the application...
    By Petike in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2008, 05:23 PM
  2. Problem with com application
    By amardon in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2005, 05:50 AM
  3. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 03:33 AM
  4. Win application not very portable
    By swed in forum Windows Programming
    Replies: 5
    Last Post: 10-01-2001, 11:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21