Can you write the following code without using any logical operators?
cout << “Are you hungry? (0-no, 1, yes) << endl;
cin >> choice;
if(choice == 1 && store == OPEN) { //get some food from the store
} else if(choice == 1 && store == CLOSED) {
//make some food at home
}
else { //I’m not hungry }
For the following C++ program, to make it run without using any conditional statements, we make use of a 2D array of strings named ans[2][2].
This array will contain all possible outcomes for values entered by the user for hungry and store. So every time, regardless of the user input ans[choice][store] will be printed.
So, if user is hungry(1) and store is closed(0) then ans[1][0] will be printed, if he is hungry(1) and store is open(1), then ans[0][1] will be printed and so on...
CODE:
#include <iostream>
using namespace std;
int main()
{
int store,choice;
//string array for all possible answers:
string ans[2][2]={ "make some food at home","make some food at
home",
"get some food from the store", "make some food at home"};
cout << "Are you hungry? (0-no, 1-yes)" << endl;
cin >> choice;
cout<<"Is store open?(0-closed, 1-open)"<<endl;
cin>>store;
cout<<ans[choice][store]; //printing the answer
return 0;
}
OUTPUT:
Can you write the following code without using any logical operators? cout << “Are you hungry?...
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...
I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...
Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;
I need help in my C++ code regarding outputting the enums in string chars. I created a switch statement for the enums in order to output words instead of their respective enumerated values, but an error came up regarding a "cout" operator on my "Type of Item" line in my ranged-based for loop near the bottom of the code. I tried casting "i.type" to both "i.GroceryItem::Section::type" and "i.Section::type", but neither worked. Simply put, if a user inputs 1 as their...
For each of the following create an expression using appropriate Logical Operators (AND, OR or NOT) The store is not open Two criteria to drive are 16 years or older Completed driver's education You can have only one meal Pizza Spaghetti You need one of the following as proof of identity to get a driver's license Passport Two of the following Birth Certificate ID Card Bill Statement with your name and address
This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order. #include <iostream> using namespace std; int main() { int num1; // holds 1st number int num2; // holds 2nd number int result; // holds result of multiplication int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number int *num2Ptr...
I have provided you with a sample class named FlashDrive which has been diagrammed below. Using the FlashDrive class provided earlier, upgrade the class so that it supports various operators. Make operator+ combine together the contents of two FlashDrive, as long as the contents does not exceed the size. Make operator- subtract one FlashDrive contents from another, as long as the size or contents don't go negative. Support the >> and << operators to allow instances to be read from...
Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) { int uniqueDigitCount = 0; int storeDigit = 0; int digit = 0; while (input > 0) { digit = 1 << (input % 10); if (!(storeDigit & digit)) { storeDigit |= digit; ...
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...
What changes should you make to the following code if you delete the “using namespace std;” cout << "Who is there ? "; cin >> name; cout << "Hello " << name << "!" << endl