Question

In: Computer Science

Write a program that does the following in order: 1. Ask user to enter a name...


Write a program that does the following in order:

1. Ask user to enter a name

2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5”

3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5”

4. If the sum is greater than 0, print out the sum

5. If the sum is equal to zero, print out “Your account balance is zero”

6. If the sum is less than 0, print out “Your account is overdrawn” and the “negative amount”

7. Round all print values to 1 decimal place

Round your sum output to 2 decimal places

Solutions

Expert Solution

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
    
    string name;
    cout << "Enter your name : ";
    cin >> name;
    cout << name << endl;
    
    float arr[5];
    cout << "Enter 5 amounts : ";
    for(int i=0; i<5; i++) {
        cin >> arr[i];
        cout << arr[i] << " ";
    }
    cout << endl;
    
    float sum = 0;
    for(int i=0; i<5; i++) {
        sum += arr[i];
    }
    
    if(sum > 0) {
        printf("%.2f\n", sum);
    }
    else if(sum == 0) {
        printf("Your account balance is zero\n");
    }
    else {
        printf("Your account is overdrawn %.1f\n", -sum);
    }
    
    
}

C++ code

ScreenShot of the code and output


Related Solutions

Using Python write a program that does the following in order: 1. Ask user to enter...
Using Python write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Write a program that does the following in order: 1. Asks the user to enter a...
Write a program that does the following in order: 1. Asks the user to enter a name 2. Asks the user to enter a number “gross income” 3. Asks the user to enter a number “state tax rate” 4. Calculates the “Federal Tax”, “FICA tax” and “State tax” 5. Calculates the “estimated tax” and round the value to 2 decimal places 6. Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Write the following program in Java. Ask the user to enter the number of rows and...
Write the following program in Java. Ask the user to enter the number of rows and columns for a 2-D array. Create the array and fill it with random integers using (int)(Math.random() * 20) (or whatever number you choose). Then, provide the user with several menu choices. 1. See the entire array. 2. See a specific row. 3. See a specific column. 4. See a specific value. 5. Calculate the average of each row. 6. Calculate the total of each...
Write a program that does the following things: in C++ 1 ) ask the user for...
Write a program that does the following things: in C++ 1 ) ask the user for 2 primary colors (red, blue, yellow) [should be in main] 2 ) determine the secondary color the 2 primarily colors make [should be in newColor function] red + blue = purple red + yellow = orange blue + yellow = green 3 ) Print the following message <color1> and <color2> makes <color3>
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If...
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If the age is greater than 21 print "welcome," and if the age is less than 21 print "sorry." Use input validation to make sure the birthdate was entered correctly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT