Thread: Simple C++ program - help needed

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    3

    Simple C++ program - help needed

    Hey guys, this is going to seem like a jumbled mess as I'm very tired and have been trying to figure this out for awhile. So, if you get irritated easily or don't have a minute or two to spare just ignore it, heh.

    I read the topics about posting, posting code, asking for help, etc. I have a legitimate need of programming help. It is for a class project in introduction to c++. We are allowed to see tutors. I have spent several hours on this program, seen a tutor at the school, and think I am at least somewhat close, but I am having some trouble puting it all together and understanding it.

    I am only a math minor (music major) and this is the only programming course I'll be taking. However, it is important I actually understand how it works and I need to write programs on in class tests, among other things. So, if you actually write me some code, it would benefit me greatly if you explained it or answered questions I might have about it.

    Ok, sorry for all the wording but I'm just trying to justify asking for help.

    Here is the program definition:

    Write a menu-driven program that will help an elementary school student learn multiplication. Use function rand to produce two positive one-digit integers. The program will ask a question such as: How much is 6 times 7?

    The student then types the answer. Your program checks the student's answer and prints the various comments:


    Responses to a correct answer:

    Excellent!
    Very Good!
    Nice work!
    Keep up the good work!

    Responses to an incorrect answer:

    No. Please try again.
    Wrong. Try once more.
    Don't give up!
    No. Keep trying.

    Use the random number generator to choose a number between 1 to 4 to select an appropriate response to each answer. Use a case select structure to issue the responses.

    The program should count the number of correct and incorrect responses typed by the student. After the student answers 10 questions, your program should calculate the percentage of correct responses.

    Then, modify the program to include two things:

    Allow the user to pick the type of arithmetic problems he or she wishes to study. An option of A means addition, S for subtraction, M for multiplication, D for division.

    Allow the user to enter a grade level capability. A grade level of 1 means only single digit numbers in the program, a grade level of 2 means to use the numbers as large as two digits, etc.



    here is what I've come up with so far.

    Code:
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    
    using namespace std;
    int main ()
    {
    
    int right=0,wrong=0;
    int leftoperand, rightoperand, response, answer, studentanswer, grade
    char category, opt
    
    cout<<"Please choose an arithmetic problem category:"<<endl;
    cout<<"A for addition, S for subtraction, M for multiplication, or D for division"<<endl;
    cin>>category
    cout<<"Now choose your grade level: 1 for single-digit numbers and 2 for two-digit numbers"<<endl;
    cin>>grade
    for(int i=0; i<10; i++)
    {
     SORRY ABOUT THIS PART- my tutor told me to use this formula, I don't entirely understand it
     but I know it will help differentiate between grade level 1 and grade level 2...
    
    leftoperand = (pow(10, grade - 1)) + rand()&#37;((pow(10,grade))-1);
    	rightoperand = (pow(10, grade - 1)) + rand()%((pow(10,grade))-1);
    
    
    
    rightoperand = (rand() %10) 
    
    answer=leftoperand*rightoperand // declaring the correct answer
    
    cout<<"How much is "<<leftoperand*rightoperand<<"?"<<endl; // asking student arithmetic questions
    cin>>studentanswer
    
    This next part is the only part I was happy with myself for, I think it is kind of close to being correct.
    Basically, it is the last half of the program without the two extra parts:
    
    for (int question=1; question<10; question++)
    {
    if (studentanswer==answer)
    {
    response = rand() %3;
    switch (response)
    {
    	right++ // increasing number of correct answers
    case 0:
    	cout<< "Excellent!"<<endl;
    	break;
    case 1:
    	cout<< "Very Good!"<endl;
    	break;
    case 2:
    	cout<< "Nice Work!"<<endl;
    	break;
    default:
    	cout<< "Keep up the good work!"<<endl;
    	break;
    }			// switch
    }			// else
    }			// for loop
    
    else (studentanswer!=answer)
    {
    response = rand() %3;
    switch (response)
    {
    	wrong++ // increasing number of incorrect answers
    case 0:
    	cout<< "No. Please try again."<<endl;
    case 1:
    	cout<< "Wrong. Try once more."<<endl;
    case 2:
    	cout<< "Don't give up!"<<endl;
    default:
    	cout<< "No. Keep trying."<<endl;
    }			// switch
    }			// else
    }			// for loop
    
    cout<<"You answered "<<right<<"questions correctly, and "<<wrong<<"questions incorrectly."<<endl;
    cout<<"This gives you a score of "<<(right/10)*100<<"out of 100"<<endl;
    
    
    return 0;
    
    }

    As you can see, the first half of the program is a mess. I am having trouble doing the parts where the user chooses the type of arithmetic problem and the grade level (1 digit or 2). I believe my program only works with multiplication at the moment. then, I am having trouble getting my program to ask the user a random question. I thought of typing up all the multiplication tables, etc, and using an if/else structure, but that has got to be the worst idea possible. I think maybe my problem is not entirely understanding the random number generator.

    I have been reading my c++ book (absolute c++) most of the day, and working on this and trying to piece it together for many hours, but apparently I just suck at programming. sorry if what I'm asking is unclear, I'm very tired at the moment. I will post more information when I wake up.

    If someone reads this and might be able to help, thanks. Otherwise, I'll add more information in the morning including what I was trying to do at various steps in the program, especially the beginning. I am willing to devote my whole weekend to getting this thing done, and am very eager to read peoples ideas and opinions.
    Last edited by CornedBee; 10-06-2007 at 03:37 AM. Reason: Broke lines in code section to preserve site layout.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  4. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 07:23 AM
  5. Help with small simple program
    By Sonor in forum C Programming
    Replies: 5
    Last Post: 04-02-2005, 07:40 AM