View previous topic :: View next topic |
Author |
Message |
FirePhoenix Grandmaster Cheater Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Mar 07, 2009 4:36 pm Post subject: First C++ program |
|
|
This is my first C++ program very simple that I made since starting 3 days ago, I didn't have any good idea's so I thought I might just make this. In addition if anyone can help me add a line in the source that makes the program calculate how many questions you got wrong and right as well as the choice of starting over or not. Here's the code.
Code: |
//attempting to create a program
#include <iostream>
using namespace std;
int main ()
{
int Iss, Blister;
cout << "Math Practice Beta: Made by FirePhoenix of CEF!\n";
cout << "\nSimply answer a few math questions, to see how good you are at Math!\n";
cout << "\n1. What is 1+1?: ";
cin >> Iss;
if (Iss == 2)
cout << "\nYou are correct!\n";
else
cout << "\nYour wrong.\n";
cout << "\n2. What is 4+4?: ";
cin >> Iss;
if (Iss == 8)
cout << "\nYou are correct!\n";
else
cout << "\nYour wrong!\n";
cout << "\n3. What is 6+6?: ";
cin >> Iss;
if (Iss == 12)
cout << "\nYou are correct!\n";
else
cout << "\nYou are wrong!\n";
cout << "\n4. What is 3+2?: ";
cin >> Iss;
if (Iss == 5)
cout << "\nYou are correct!\n";
else
cout << "\nYou are wrong!\n";
cout << "\n5. What is 4+5?: ";
cin >> Iss;
if (Iss == 9)
cout << "\nYou are correct!\n";
else
cout << "\n You are wrong!\n";
cout <<"\nYou have completed all questions nice job, press any key to close\n";
cin >> Blister;
return 0;
}
|
_________________
Currently learning C++. You can't stop me babe!!! |
|
Back to top |
|
|
hcavolsdsadgadsg I'm a spammer Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Mar 07, 2009 4:45 pm Post subject: |
|
|
Why don't you randomly generate the problems?
Just loop until the user feels like stopping.
|
|
Back to top |
|
|
FirePhoenix Grandmaster Cheater Reputation: 0
Joined: 22 Jan 2008 Posts: 575
|
Posted: Sat Mar 07, 2009 8:41 pm Post subject: |
|
|
slovach wrote: | Why don't you randomly generate the problems?
Just loop until the user feels like stopping. |
Well yea but I wanted it to be this way.
_________________
Currently learning C++. You can't stop me babe!!! |
|
Back to top |
|
|
hacksign23 Master Cheater Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Thu Mar 19, 2009 5:57 pm Post subject: |
|
|
kinda crappy, put good first program.
i suggest using a better method such as functions or something, idk.
_________________
|
|
Back to top |
|
|
me Grandmaster Cheater Reputation: 2
Joined: 24 Jun 2004 Posts: 733 Location: location location
|
Posted: Thu Mar 19, 2009 6:24 pm Post subject: |
|
|
god I am rusty on this, virtually forgot c++ or much of any programming,, been a long time lol..
anyway if you want to just edit this program instead of looping you could try making another varible called INT correctsum or whatever you want to call the varible,
then have
if (Iss == 2)
cout << "\nYou are correct!" << correctsum = correctsum + 1 <<\n;
else
else
cout << "\nYour wrong.\n";
you can make varibles to keep a check on the wrong numbers as well in much the same way,
say if there is a wrong answer
INT wronganswer
wronganswer = wronganswer +1
that sort of thing
goodly godly I need a refresher course
hope that gave you a simple idea or two
_________________
|
|
Back to top |
|
|
Archion Newbie cheater Reputation: 0
Joined: 03 Jan 2009 Posts: 16 Location: Within the Vaginal Portal of Kate Perry.
|
Posted: Thu Mar 26, 2009 10:51 am Post subject: |
|
|
Oh crud..
I don't even know how to hack or to understand em' program C++ things... Yet. *Sob*
_________________
Sweet Nibblets!!!
(NOTE): You wasted 30 seconds of your precious life from reading the useless Hannah Montana quote. If you want to do good, look good, and feel good!!! Rep meh!!! :'D |
|
Back to top |
|
|
&Vage Grandmaster Cheater Supreme Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Mar 26, 2009 2:11 pm Post subject: |
|
|
You should use switch and cases =D
|
|
Back to top |
|
|
Anden100 Grandmaster Cheater Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Thu Mar 26, 2009 3:01 pm Post subject: |
|
|
Unlimited!, just a few Math Questions
Code: | #include <iostream>
int main(){
std::cout << "Attempt to calculate the following:\n";
int nr1, nr2, result;
while(true){
nr1 = rand() % 20;
nr2 = rand() % 20;
std::cout << nr1 << " + " << nr2 << " = ";
std::cin >> result;
if(result == nr1 + nr2)
std::cout << "Correct!\n\n";
else
std::cout << "Sorry, the correct answer was: " << nr1 + nr2 << ", try a new one!\n\n";
}
return 0;
} |
|
|
Back to top |
|
|
samo502 Master Cheater Reputation: 0
Joined: 14 Mar 2008 Posts: 342 Location: That place.
|
Posted: Fri Apr 24, 2009 12:53 pm Post subject: Re: First C++ program |
|
|
FirePhoenix wrote: | In addition if anyone can help me add a line in the source that makes the program calculate how many questions you got wrong and right as well as the choice of starting over or not. | Simple, Code: | //(declarations)
//I prefer using a byte for this particular variable because it takes up less space than an int
byte quesWrong = 0;
//any time the user gets one wrong
quesWrong++; //not sure if a semicolon goes here or not exactly, I don't use this function much. Anyway in case you didn't know adds quesWrong + 1
//at the end of the quiz
cout<<"You got "<<quesWrong<<" wrong."<<endl; | The code above is from memory and may not exactly be right.
|
|
Back to top |
|
|
Jani Grandmaster Cheater Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun May 03, 2009 12:26 pm Post subject: |
|
|
Anden100 wrote: | Unlimited!, just a few Math Questions | You forgot to ::srand, faulty input will harm your program and I'd prefer for(;;) over while(true). :)
|
|
Back to top |
|
|
LolSalad Grandmaster Cheater Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
Posted: Mon May 04, 2009 12:34 am Post subject: Re: First C++ program |
|
|
samo502 wrote: | byte quesWrong = 0; |
I'm assuming that most if not all compilers would require Code: | typedef unsigned char byte | beforehand, or they could just use Code: | unsigned char quesWrong = 0; |
_________________
|
|
Back to top |
|
|
LaBe1 Master Cheater Reputation: 0
Joined: 14 Jun 2007 Posts: 380
|
Posted: Fri Sep 18, 2009 5:29 am Post subject: |
|
|
Here are a few of my first programs. while taking the class and following the book of course.
Sources are included, along with an explanation on what they do and how to use them.
http://rapidshare.com/files/281730343/First_C___Programs.rar
_________________
R.I.P. : UberHaxorz, ClericFoSho |
|
Back to top |
|
|
samo502 Master Cheater Reputation: 0
Joined: 14 Mar 2008 Posts: 342 Location: That place.
|
Posted: Mon Sep 21, 2009 12:49 pm Post subject: |
|
|
An improved version of Anden100's code:
Code: | #include <iostream>
#include <ctime> //the library for time
#include <cstdlib> //allows usage of srand
using namespace std; //so you don't have to use std:: every time
int main()
{
srand(time(0)); //seeds the random numbers based on the time
system("title Math Problem Generator"); //changes window title
int nr1, nr2, result;
int quesamount = 0, quesnum = 0, queswrong = 0, quesright = 0; //gives odd error if they don't all say = 0 for some reason here.
cout << "How many questions do you want to be asked? ";
cin >> quesamount;
quesamount++; //adds one to quesamount so it asks the right amount
system("cls"); //clears the screen so only the problems display
for(quesnum = 1; quesnum < quesamount; quesnum++) //loops until the question number equals or is above the amount
{
nr1 = rand() % 20 + 1;
nr2 = rand() % 20 + 1; //+ 1 to make sure it never asks with 0(too easy =P)
cout << "Question " << quesnum << ":\n" << nr1 << " + " << nr2 << " = ";
cin >> result;
if(result == nr1 + nr2)
{
cout << "Correct!\n" << endl;
quesright++; //adds to the questions answered right
}
else
{
cout << "Sorry, the correct answer was: " << nr1 + nr2 << ", try a new one!\n" << endl;
queswrong++; //adds to the questions answered wrong
}
}
cout<< "You got " << quesright << " right, and " << queswrong << " wrong." << endl;
system("pause"); //puts Press any key to continue... on screen
return 0;
} |
|
|
Back to top |
|
|
|