Advertisement

hmm what's wrong with this

Started by December 13, 2002 04:35 PM
8 comments, last by tristantheone 21 years, 11 months ago
#include <iostream> #include <stdlib.h> #include <stdio.h> int main(){ char answer; cout <<"hello"<<endl<<"this is a test"<<endl<<"say something"; cin answer; cout <<"this is what u have answered"<<answer; cin.get(); return 0; } it only gives one error and it has something to do with the variable "answer"
cout <<"hello"
cin >> answer;

I think you should split that line of code into this. Unless there is another way to code it.

[edited by - CodeMaster000 on December 13, 2002 5:40:20 PM]
Advertisement
quote: Original post by CodeMaster000
cout <<"hello"
cin >> answer;

I think you should split that line of code into this. Unless there is another way to code it.

<SPAN CLASS=editedby>[edited by - CodeMaster000 on December 13, 2002 5:40:20 PM]</SPAN>


ah yea how could i be this dumb
and yes other question how do you program so that for example
if button q is pressed (no other button then q )the program ends and else it doesnt end??
quote: Original post by CodeMaster000
cout <<"hello"
cin >> answer;

I think you should split that line of code into this. Unless there is another way to code it.

[edited by - CodeMaster000 on December 13, 2002 5:40:20 PM]


ah yea how could i be this dumb
and yes other question how do you program so that for example
if button q is pressed (no other button then q )the program ends and else it doesnt end??
maybe this is what you want to do?

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

int main(){
int answer; //this can be changed to some other type
char answer;
cout <<"hello";
cin >>answer;
cout <<"this is what u have answered"<return 0;
}
you would go

if (answer =="q") {cout<<"Goodbye");

i think
Advertisement
quote: Original post by Maewein
you would go

if (answer =="q") {cout<<"Goodbye");

i think


I don''t think this is what he is looking for, I think what they want to do is have the loop the program until the user only puts the letter "q"

for that you need to use a
repeat until or a do while loop



Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
Turt99, you might want to make people aware that Mozilla/Netscape users aren''t going to see much on your page. It appears to only work well with IE.

Tristan, I''d recommend you check out some basic C++ books from your local library. They won''t turn you into an overnight expert, but they do cover things like what you''re asking.
"We are born naked, wet, and hungry. Then things get worse."
Maybe this is something that you have been looking for...

#include <iostream>
using namespace std;

int main()
{
char answer;
cout<<"Press q to quit...";

// Run loop until the q has been pressed
do
{
// Read the keyboard
cin>>answer;
} while(answer!=''q'' && answer!=''Q'');

cout<<"Finally you found the right key!!";
return 0;
}
Cogito cogitis ille exit(0); postquam ubi venit, et non est modo "return 0;".

This topic is closed to new replies.

Advertisement