Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to use string in if else statement c++

double const FRAME_COST = 45.00;
string input;
char yes,
     no;
int frames;


cout << "Do you want additional frames? Type yes/no:  ";
cin  >> input;

    if (input == yes){
       cout << "How many?"
       cin >> frames;
       frames = frames * FRAME_COST;
       }

// The problem is in **the if statement**
// I need to use a string not a bool (according to my professor)
// I can't get the compiler to recognize the **if statement**
// I realize this isn't practical, but he always throws curve balls.
Comment

how to use string in if else statement c++

const string YES = "yes";
const string NO = "no";
const double FRAME_COST = 45.0;


int main()
{
    string input;
    double frames;
    cout << "Hello World" << endl; 
    cin >> input;

    if(input == YES)
    {
        cout << "How many?" << endl;
        cin >> frames;
        frames = frames * FRAME_COST;
        cout << frames << endl;
   }

   return 0;
}
Comment

how to use string in if else statement c++

if (input == "yes") {
    ...
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: convert datatype of field db browser from text to timedate db browser 
Cpp :: passing reference to thread c++ 
Cpp :: logisch nicht 
Cpp :: multi variable assignment cpp 
Cpp :: zsh: segmentation fault ./provided_files.exe erosion X . 
Cpp :: Check whether K-th bit is set or not c++ 
Cpp :: c++ vector allocator example 
Cpp :: Polycarp found a rectangular table consisting of n rows and m columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": codeforces solution 
Cpp :: number of characters in string 
Cpp :: cin une énumération 
Cpp :: omp multiple reductions 
Cpp :: input many numbers to int c++ 
Cpp :: how to compile with libstdc++ fedora 
Cpp :: Chef and the Wildcard Matching codechef solution in c++ 
Cpp :: set precision on floating numbers 
Cpp :: 400 watt hour per kg 
Cpp :: return multiple objects from a function C++ using references 
Cpp :: operator overloading prefix postfix c++ 
Cpp :: how to adjust and delete memory in c, c++ 
Cpp :: ranged based for loop c++ 
Cpp :: copy constructor in c++ questions 
Cpp :: github static std::string gen_name() { } // To do static int gen_number() { } // To do static int gen_grade() { } // To do double compute average() { } // To do 
Cpp :: find a member variable in a vector of objects cpp 
Cpp :: how to make a running text in c++ 
Cpp :: Problems in your to-do list codechef solution in c++ 
Cpp :: how to define global array in c++ in a scope 
Cpp :: namespace c++ 
Cpp :: get array size 
Cpp :: c++ sort a 2d vector by column 
Cpp :: how to call subclass override method in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =