I'm a beginner at c++ programming, and i cant figure out how to change what cout is, depending on what the user of the program inputs. My program asks a yes or no question, and if the user inputs <const char string[80] = ("yes")> cout will say something different as opposed to if the user inputs <const char string[80] = ("no")>
#include <iostream>
using std::cout; // program uses cout
using std::cin; // proram uses cin
using std::endl; // program uses endl
int main() // function main begins program execution
{
float money; // creates integer for money input
int PENNY = 1; //creates integer for penny
int DIME = 10; // creates integer for dime
int QUARTER = 25; // creates integer for quarter
int NICKEL = 5; // creates integer for nickel
int total = 0; // creates integer for total and initializes it
int choice = 0; // creates integer for choice and initializes it
cout << "Please enter in a dollar amount to convert it to change\n"; //prompts user
>> cin >> money; // user enters dollar amount
cout << endl; //end prompt
cout << "To determine how many pennies, dimes, quarters or nickels, enter\n"; //display message
cout << "MENU\n"
<< "1) PENNY\n" //user inputs 1 for penny conversion
<< "2) DIME\n" //user inputs 2 for dime conversion
<< "3) QUARTER\n" //user inputs 3 for quarter conversion
<< "4) NICKEL" << endl; //user inputs 4 for nickel conversion
cin >> choice; //user enters number corresponding to coin
cout << endl; //end prompt
{
if ( money <= 1 ) // if money input is 1 or less
return -1; // end program
}
{ // begin if...else
if ( choice == 1 ) //if user chooses 1 for penny then
total = (int)( money * 100 ) / PENNY; // multiply money times 100 divided by 1 to get pennies
elseif ( choice == 2 ) //if user chooses 2 for dime then
total = (int)( money * 100 ) / DIME; // multiply money times 100 divide by 10 to get dimes
elseif ( choice == 3 ) //if user chooses 3 for quarter then
total = (int)( money * 100 ) / QUARTER; //multiply money times 100 divide by 25 for quarters
elseif ( choice == 4 ) //if user chooses 4 for nickel
total = (int)( money * 100 ) / NICKEL; //multiply money times 100 divide by 5 for nickels
if ( choice == 1 ) //if user choice was 1 display conversion and message
cout << "The result is: " << total << " PENNIES in " << "$" << money << endl; // display message with amount of coins and money input
elseif ( choice == 2 ) //if user choice was 2 display conversion and message
cout << "The result is: " << total << " DIMES in " << "$" << money << endl; // display message with amount of coins and money input
elseif (choice == 3 ) //if user choice was 3 display conversion and message
cout << "The result is: " << total << " QUARTERS in " << "$" << money << endl; // display message with amount of coins and money input
elseif ( choice == 4 ) //if user choice was 4 display conversion and message
cout << "The result is: " << total << " NICKELS in " << "$" << money << endl; // display message with amount of coins and money input
} // end if..else
system("pause"); // keep window open
return 0; // indicates successful termination
}
#include <iostream>
usingnamespace std; // uses std namespace
int main() // function main begins program execution
{
char choice = 0; // creates character for choice
char y = 0; // creates character for y
char n = 0; // creates character for n
cout << "Would you like some advice?\n"; // display question to user
cout << "Y for yes and N for no\n"; // prompts user for a Y or N
cin >> choice; // user enters in letter
switch ( choice ) // switch statement to determine what input letter and what to display based on input
{
case'y': // lower case choice for y
case'Y': // upper case choice for Y
cout << "\nLook before you leap.\n"; // message displayed if user inputs Y or y
break; // exit switch
case'n': // lower case choice for n
case'N': // upper case choice for N
cout << "OK then. No advice for you!\n"; // message displayed if user inputs N or n
break; //exit switch
default: // call all other characters
if ( choice != y || n ) // if the choice is not a y or n display below message
cout << "Sorry only Y or N is allowed.\n"; //message displayed if condition is not met
cout << endl; //output a newline
} // end switch
cout << "Have a nice day!\n"; //display message outputted with each choice
cout << endl; //output a newline
system("pause"); // keeps window open, best used for learning codes, poses security vulnerability
return 0; // indicate successful termination
} // end function main