what is the initializer i need? the error is in the line on top of the "while(1)" line. I looked online and it looked like all they did was add the int in front of QuestionNumber.
I also have a link to my code, there were 2 other errors i had. i'm new to c++ http://cpp.sh/5e6gf
#include <iostream>
#include <string>
int main()
{
std::string Responce;
std::string A;
std::string B;
std::string C;
std::string D;
std::string QuestionNumber;
std::string Name
int QuestionNumber = 1;
While (1)
while (QuestionNumber=1){
std::Cout <<"what element is your favorite?" ;
std::cout << "A. Fire""\N" ;
std::cout <<"B Ice \N" ;
std::cout << "C. Water" << "\N" ;
std::cout << "D. Wind""\N" ;
getline(std::cin,Response);
while(Response="A"){
std::Cout << "So, you're a fire weilder then? huh, took you for more a wind one. >> oh how rude of me, what was your name again?" ;
}
while(Response="B"){
std::cout << "Ice? really? huh, i guess you deserve the cold shoulder then. Kidding! what is your name anyways?" ;
}
while(Response= "C"){
std::cout << "water? what are you waiting for, tell me your name" ;
}
while(Response= "D"){
std::cout << "wind? you must be the boring one then. no? okay, fine, what is your name then?" ;
}
}
return 0
};
what is this initializer i need? I made question number, and the a, b, c, d global vareables, so they could be reused throughout the program thats why they're before int main.
#include <iostream>
#include <string>
std::string Responce;
std::string A;
std::string B;
std::string C;
std::string D;
std::string QuestionNumber;
std::string Name
int main(){
while (1)
QuestionNumber = 1;
while (QuestionNumber=1){
std::cout <<"what element is your favorite?" ;
std::cout << "A. Fire" ;
std::cout <<"B Ice" ;
std::cout << "C. Water" ;
std::cout << "D. Wind" ;
getline(std::cin,Response);
while(Response="A"){
std::cout << "So, you're a fire weilder then? huh, took you for more a wind one. >> oh how rude of me, what was your name again?" ;
}
while(Response="B"){
std::cout << "Ice? really? huh, i guess you deserve the cold shoulder then. Kidding! what is your name anyways?" ;
}
while(Response= "C"){
std::cout << "water? what are you waiting for, tell me your name" ;
}
while(Response= "D"){
std::cout << "wind? you must be the boring one then. no? okay, fine, what is your name then?" ;
}
}
};
#include <iostream>
int main() {
bool keep_looping = true ;
while(keep_looping) {
std::cout << "\n\nwhat element is your favourite?\n"
<< "A. Fire\nB. Ice\nC. Water\nD. Wind\nQ. Quit\n? " ;
char response ;
std::cin >> response ;
switch(response) {
case'A': case'a':
std::cout << "So, you're a fire wielder then? huh, took you for more a ""wind one. >> oh how rude of me, what was your name again?\n" ;
break ;
case'B': case'b':
std::cout << "Ice? really? huh, i guess you deserve the cold shoulder ""then. Kidding! what is your name anyway?\n" ;
break ;
case'C': case'c':
std::cout << "water? what are you waiting for, tell me your name\n" ;
break ;
case'D': case'd':
std::cout << "wind? you must be the boring one then. no? ""okay, fine, what is your name then?\n" ;
break ;
case'Q' : case'q':
keep_looping = false ;
break ;
default:
std::cout << "invalid input. try again\n" ;
}
}
}
Case is a keyword used in a switch statement it means a case
lets say if you use an if statement
1 2 3 4
if(a == b){
// do something ..
}
lets say that both are and b are the same number then this if statement gets executed,this is the same in a switch statement except you use the keyword case,so lets say you pass 2 to the switch statement,you can use different cases instead of creating multiple and messy looking if or else if statements,
Q is just the test case like a or b in the if statement
there is a function that outputs the question and receives the answer (void question)
there is a function that determines the results (void results)
and a function that outputs if the question number is not one(void error)
the parameters for void question() and void results() were the answer that the user chose, the ampersand is pass by reference and it allows the character to be modified in the function
#include <iostream>
#include <string>
void question(char& ans);
void results(char& ans);
void error();
int main()
{
char answer;
int questionNum = 1;
questionNum == 1 ? question(answer) : error();
}
void question(char& ans)
{
std::cout << "What element is your favorite?\n";
std::cout << "A. Fire\n"
<< "B. Ice \n"
<< "C. Water \n"
<< "D. Wind\n";
std::cin >> ans;
results(ans);
}
void results(char& ans)
{
switch (ans) {
case'A':
case'a':
std::cout << "So, you're a fire wielder then? huh, took you for more a ""wind one. oh how rude of me, what was your name again?\n";
break;
case'B':
case'b':
std::cout << "Ice? really? huh, i guess you deserve the cold shoulder ""then. Kidding! what is your name anyway?\n";
break;
case'C':
case'c':
std::cout << "water? what are you waiting for, tell me your name\n";
break;
case'D':
case'd':
std::cout << "wind? you must be the boring one then. no? okay, fine, what is your name then?\n";
break;
}
}
void error()
{
std::cout << "Question number is not 1";
}