|
Code
Sept 17, 2014 20:30:10 GMT -5
Post by Rikka on Sept 17, 2014 20:30:10 GMT -5
#include<iostream>
using std::cout; using std::endl;
int main() { int a;
a = 1;
cout << "a = " << a << endl; cout << endl; if (a = 1) { cout << "Once more onto the breach." << endl; } else if (a = 2) { cout << "Twice the speed of life." << endl; } else if (a = 3) { cout << "Three times are not enough..." << endl; } else if (a = 4) { cout << "Four times the fun!" << endl; } cout << endl;
return 0; }
|
|
|
Code
Sept 17, 2014 20:33:58 GMT -5
Post by Horo on Sept 17, 2014 20:33:58 GMT -5
#include<iostream>
using std::cout; using std::endl; using std::cin;
int main() { int a;
//a = 1; cout << "input a: "; cin >> a;
cout << "\na = " << a << endl; cout << endl;
|
|
|
Code
Sept 17, 2014 20:38:46 GMT -5
Post by Rikka on Sept 17, 2014 20:38:46 GMT -5
#include<iostream>
using std::cout; using std::endl; using std::cin;
int main() { int a;
//a = 1; cout << "Commander, Please indicate which plan 1 through 4 to use: "; cin >> a;
cout << "\nplan = " << a << endl; cout << endl;
if (a <= 1) { cout << "Once more onto the breach." << endl; } else if (a <= 2) { cout << "Twice the speed of life." << endl; } else if (a <= 3) { cout << "Three times are not enough..." << endl; } else if (a <= 4) { cout << "Four times the fun!" << endl; } cout << endl;
return 0; }
|
|
|
Code
Sept 17, 2014 20:49:58 GMT -5
Post by Horo on Sept 17, 2014 20:49:58 GMT -5
int a; cout << "Commander, Please indicate which plan 1 through 4 to use:"; cin >> a; cout << "\nplan = " << a << endl; cout << endl;
switch (a){ case 1:cout << "Once more onto the breach.\n"; break; case 2:cout << "Twice the speed of life." << endl; break; case 3:cout << "Three times are not enough..." << endl; break; case 4:cout << "Four times the fun!\n"; break; default:cout << "That's a terrible plan!\n"; break; } cout << "\n"; //This is also a new line character. It works just like endl;
|
|
|
Code
Sept 17, 2014 21:05:39 GMT -5
Post by Rikka on Sept 17, 2014 21:05:39 GMT -5
#include<iostream>
using std::cout; using std::endl; using std::cin;
int main() { int a;
cout << "Commander, Please indicate which plan 1 through 4 to use: "; cin >> a;
cout << "\nplan = " << a << endl; cout << endl;
if (a == 1) { cout << "Once more onto the breach." << endl; } else if (a <= 0) { cout << "Commandar there is no plan for that number." << endl; } else if (a == 2) { cout << "Twice the speed of life." << endl; } else if (a == 3) { cout << "Three times are not enough..." << endl; } else if (a == 4) { cout << "Four times the fun!" << endl; } else if (a > 4) { cout << "Commander there is no plan for that number." << endl; }
cout << endl; return 0; }
|
|
|
Code
Sept 18, 2014 14:46:50 GMT -5
Post by Horo on Sept 18, 2014 14:46:50 GMT -5
int a;
cout << "Commander, Please indicate which plan 1 through 4 to use: "; cin >> a; cout << "\nplan = " << a << endl << endl; //cout << endl; // I moved this into the above line to shorted the length of your code
if (a == 1) //I removed the brackets since you don't need them if your if/else is only excuting one line cout << "Once more onto the breach." << endl; else if (a == 2) cout << "Twice the speed of life." << endl; else if (a == 3) cout << "Three times are not enough..." << endl; else if (a == 4) cout << "Four times the fun!" << endl; else //else means that if there is any condition that isn't solved above, this will exicute cout << "Commander there is no plan for that number." << endl; cout << endl;
|
|
|
Code
Sept 18, 2014 14:50:32 GMT -5
Post by Horo on Sept 18, 2014 14:50:32 GMT -5
Rikka, I didn't test run your code, but it should work perfectly fine.
I've made another round of revisions. The only major on being that I removed the
if(a <=0) and the if(a>4) lines and combined them into one else statement.
Else Statements will exciute if the above if failed. This is what happens when you do an else if()
if I was to put brackets to it
if() {} else { if() {} else{ if() {} else } } where the last bracket is the end of your first else statement.
If this doesn't make sense, let me know!
|
|