Home
Help
Search
Calendar
Login
Register
Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
New forum theme up and running!
Charas-Project
»
Off-Topic
»
Archive
»
Really Old Stuff
»
General programming
»
ok i need loop help
« previous
next »
Print
Pages: [
1
]
Author
Topic: ok i need loop help (Read 3608 times)
maxine
Average scripter
Zealot
Posts: 736
求ude i am 16 with 2 balls and hair
ok i need loop help
«
on:
October 21, 2005, 03:04:51 PM »
Ok here is a c++ simple made if else test
// Just a test math simple
#include
using namespace std;
main()
{
double answer;
cout << "1. what is 5 x 5?: ";
cin >> answer;
if (answer == 25){
cout << "Ur right mate";
}
else {
cout << "Ur wrong";
}
cin.ignore(1000,'\n');
getchar ();
return 0;
}
I want too know how too put a loop so if you answer the wrong answer it jumps too the beginning so it starts over you know?. I think it should have something with "while" loop too do but i dont get "while" so good plz help (A)
Logged
Drighton
Acolyte
Posts: 419
(No subject)
«
Reply #1 on:
October 21, 2005, 04:14:23 PM »
If I remeber correctly:
"What is 5 x 5"
get input (with cin??)
While (input != right answer (25) )
{
"Wrong! Try again."
get input (with cin??)
}
"You are Right!! Have a cookie."
.. yeah, but thats pseudocode. I've not written in C++ in forever. But if you know what I'm trying to do, you can replace the pseudocode. Hope that helps.
EDIT: I'll just edit your code. :p Now With 33% more Comments!
main()
{
double answer;
cout << "1. what is 5 x 5?: "; // Output
cin >> answer; //Get input
while (answer != 25) //Loop while answer is wrong
{
cout << "Ur wrong"; // Output
cout << "1. what is 5 x 5?: "; // As Q again
cin >> answer; // Get input again
}
cout << "Ur right mate"; // Output
cin.ignore(1000,'\n'); // WTH is this!!!???
getchar (); // yeah.
return 0; // should it be int main() for this??
}
Logged
maxine
Average scripter
Zealot
Posts: 736
求ude i am 16 with 2 balls and hair
(No subject)
«
Reply #2 on:
October 21, 2005, 05:57:50 PM »
int main is gonna be up where main is i didnt put it there. Cin ignore ignores all cin pieces so you can watch the program in a black box. Thanks i get the idea
Edit: or actually i dunno.. But the teacher said it was gonna be there so i guess it has something with the test too do. (when you are gonna test ur program)
Logged
maxine
Average scripter
Zealot
Posts: 736
求ude i am 16 with 2 balls and hair
(No subject)
«
Reply #3 on:
October 22, 2005, 07:50:57 AM »
Hey drighton ive got another question for you PRO
. You can still answer 25,1 25,3 etc and its right as long as it got with 25 too do. I know the problem and thats cuz i made a "double" but whats it gonna be there instead? thanks mate you are really helping me =)
Logged
Drighton
Acolyte
Posts: 419
(No subject)
«
Reply #4 on:
October 22, 2005, 02:18:40 PM »
If you mean what type of variable it needs to be, then probably integer.
CODE
--------------
main()
{
int answer;
--------------
like that
Logged
maxine
Average scripter
Zealot
Posts: 736
求ude i am 16 with 2 balls and hair
(No subject)
«
Reply #5 on:
October 22, 2005, 03:30:10 PM »
no, i meant like this. I am using this
double answer <--- double. But with double you can still answer 70,1 or 70,2 etc.. But the answer is gonna be 70. You know there is like double, float etc.. But i dont know which one to use so the program only reads integer numbers and not the decimals. You know what i mean?
Logged
Drighton
Acolyte
Posts: 419
(No subject)
«
Reply #6 on:
October 22, 2005, 04:03:14 PM »
So you want the user to be able to input decimal numbers.
like 5x5 = 25.5 ?
if so, then use float. I think... :p
I might have slept through that class. I also slept through or missed the class on Classes
which I regret.
If this don't work, ask Osmose. He may be of better help.
Logged
maxine
Average scripter
Zealot
Posts: 736
求ude i am 16 with 2 balls and hair
(No subject)
«
Reply #7 on:
October 23, 2005, 07:19:48 AM »
hehe ok yeah you didnt quite get it, or maybe i am so bad at explaining =). But you've been to help, thank you. I might come back with more to you but this topics now closed =) thanks again
Logged
Print
Pages: [
1
]
« previous
next »
Charas-Project
»
Off-Topic
»
Archive
»
Really Old Stuff
»
General programming
»
ok i need loop help