Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 18th, 2004, 5:53 AM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Write a program to test the user on a multiplication table, asking them to enter the multiplication table he/she wants and then asking them to enter the answer to each of the 12 multiplications and printing the string “Correct” or “Incorrect” as appropriate.

I was able to solve the proram, but I want to add one more thing, I need to have the option for the user to exit any time he/she wants.

I tried adding the else if (number == 100 ) return (0);

But it seems to ignore it.

Can anyone help?

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
 *
 *
 *
 *int number, result;
 *int i;
 *
 *cout << "Please Enter a number:" << endl;
 *cin >> number;
 *
 *for ( i=1;i<=12;i++)
 {
 * *
 * *cout << number << " * " << i << " = ";
 * *cin >> result;
 * *
 * *if ( result == i * number)
 * *cout << "Correct Answer " <<endl;
 * *
 * *else
 * *cout << "Incorrect Answer, Please Try Again" << endl;
 * *
 
} * *
 *
 *
 *system("PAUSE");	
 *return 0;
}
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 18th, 2004, 6:49 AM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 579
Rep Power: 5 Benoit is on a distinguished road
You post a lot of homework assignments <_< I'm not sure about C++, but in C you use exit(0);
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Oct 18th, 2004, 8:09 AM   #3
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Quote:
Originally posted by Benoit@Oct 18 2004, 10:49 AM
You post a lot of homework assignments <_< I'm not sure about C++, but in C you use exit(0);


Do You mind?? <_<


The assignment is solved, I want to add this is an extra work.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 18th, 2004, 9:08 AM   #4
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Ok guys I managed to do something, maybe not professional but it does what I want for now.

Thanks.

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
 
 
 
 int number, result;
 int i;
 
 cout << "Please Enter a number:" << endl;
 cin >> number;
 
 for ( i=1;i<=12;i++)
{
  if (number == -1 ) return(0);
  
  cout << number << " * " << i << " = ";
  cin >> result;
  if (result == -1 ) return(0);
     
  if ( result == i * number)
  cout << "Correct Answer " <<endl;
  
  else
  cout << "Incorrect Answer, Please Try Again" << endl;
  

}  
 
 
 system("PAUSE"); 
 return 0;
}
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 18th, 2004, 10:23 AM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Why not use a while loop. Have a menu that gets looped unless the number that the user enters is like zero or somthing like that. That why your program has room for other stuff later, with little work. Then inside the while loop have a switch. The user input gets fed into the switch and they get to go the different parts of the program. So somthing like this:


#include <iostream.h>    
#include <conio.h>  

int main()
{

int input;
         While (x<>4)
         {
                cout<<"1 Math Test";
                cout<<"2 Play a Game";
                cout<<"3 Other Stuff";
                cout<<"4 Exit";
                cout<<"What do you want to do?";
                cin>>x;

                switch (x)
                {
                      case 1: math_test();
                                 //Insert your code for math test here.
                                 break;
                      case 2: play_game();
                                  //Insert game code here.
                                  break;
                      case 3: other_stuff();
                                  //Yeah i think you get the idea.
                                  break;
                      case 4: 
                                  return 0;
                                  break;
                      default:
                                 cout<<"Bad Input, Please Try Again....";
                 }
        }
return 0;
}

Anyways, i havn't tested that code, it was more of a thing to give you an idea. Cheers.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 18th, 2004, 2:42 PM   #6
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Thanks Pizentios for sharing, I'll make sure that I will test it.

Cheers.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Old Oct 18th, 2004, 5:32 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
No Prob. With your current code, you really don't need it since your program does only one thing. I guess you could add some other math testing funtions. like adding and such.

Also i can see somthing that could be changed in my code. i edited the post and changed it, just amkes it a little cleaner.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Oct 19th, 2004, 3:04 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Also, with Pizentios's code, you might wanna change (x<>4) to (x!=4) - this is C++ here.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Oct 19th, 2004, 4:17 PM   #9
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Sorry, i am used to vb and PHP. Heh, i don't get to use my ~outdated~ knowledge of c++ very offten. It's sad really. Kinda like a Dog that a kid forgets about because they got a xbox for christmas.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:41 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC