Flash card

This is a discussion on Flash card within the C++ Programming forums, part of the General Programming Boards category; How can I add the following conditions: 1) Make the child ask for a new problem. 2) Display score as ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    Angry Flash card

    How can I add the following conditions:

    1) Make the child ask for a new problem.
    2) Display score as percent (numberRight/numberAttempted*100)
    3) Ability child to end the program.

    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    	int n,i;
    	int x,y;
    	int answer;
    	int wrong=0;
    
    	cout << "Answer Each of the Following: \n";
    
    
    
    	n=1;
    	for(i=0;i<n;i++)
    	{
    		x=(rand()%10);
    		// select two random numbers to ask
    		y=(rand()%10);
    
    		cout << x << " * " << y << " = ";
    		cin >> answer;   // get the answer
    
    		if(answer!=x*y)
    		{
    			cout << "Wrong. Correct answer = " <<
    			x*y << endl;
    			wrong=wrong+1;
    		} // if statement
    
    	} // for loop
    
    	cout << "Score = " << (n-wrong)*100/n << "%\n";
    	
    	cout << "Do you want to play again?";
    	
    /*	char k;
    	cout << "Do you want to play again?";
    	cin >> k;
    	
    	if(k=="Y")
    	{
    		cout << x << " * " << y << " = ";
    		cin >> answer;   // get the answer
    	}
    	
    	else
    	{
    		break;
    	}
    */		
    
    	return 0;
    
    } // main
    Thanks

  2. #2
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >1) Make the child ask for a new problem.
    >3) Ability child to end the program.
    You have to *have* a child first. I don't see any forkage going on in your code. Or by 'child' do you mean 'user'? Just so you know, in programming terminology, 'child' is used to mean a new process forked off of a parent process using fork or CreateProcess, or something similar. Anyway, throw everything in a loop and provide a menu system:
    Code:
    int main ( ) {
      ...
      while (true) {
        cout<<"Quit? ";
        if ((answer = cin.get()) && (answer == 'y' || answer == 'Y'))
          break;
        cin.ignore(); // Die, little newline, torment us no further!
        ...
      }
      ...
    }
    Just so you know, the ...'s mean 'the rest of your code goes here'.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>if(k=="Y")
    should be
    >>if(k=='Y')
    note the single quotes instead of double, which are used when comparing a single character.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 11:06 AM
  2. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 05:07 AM
  3. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  4. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 04:21 AM
  5. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 09:07 PM

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