Question

Write a C++ program to ask the user to provide a slope. If the slope is...

Write a C++ program to ask the user to provide a slope. If the slope is less then 0.5, set a variable named flag to 0, else, assign the value of 1 to the variable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream> 
using namespace std; 
  
// Driver code 
int main() 
{ 
    double slope;//declaring our variable holding slope
    
    int flag;//variable to be set depending on the value of slope

    //Prompt the user to enter slope value
    cout<<"Enter the value of slope : ";
    cin>>slope;

    //performing conditional checks and assigning value to variable flag
    if(slope<0.5){
        flag = 0;
    }
    else{
        flag = 1;
    }

    //displaying the value of flag:
    cout<<"The value of flag variable is : "<<flag<<endl;

    
  
    return 0; 
} 

[Pratyushs-MacBook-Pro:cpp pthapli$ g++ testing.cpp [Pratyushs-MacBook-Pro:cpp pthapli$ ./a.out Enter the value of slope : 0.

1 #include <iostream> using namespace std; 2 3 4 5 // Driver code int main() 6 { 7 double slope;//declaring our variable hold

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to ask the user to provide a slope. If the slope is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python code Write a program that will ask the user to input two strings, assign the...

    Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)

  • Write a program in c++ that ask a user for following information AgentID an Int Price...

    Write a program in c++ that ask a user for following information AgentID an Int Price a float HouseType a string write the information to a file named AgentComission.txt and then read that information from file and display it on screen.

  • In C using (printf and scanf) Write a program to ask the user for the weight...

    In C using (printf and scanf) Write a program to ask the user for the weight of a package, and display the shipping charges for the package. If the weight of the package is less than or equal to 0 pounds, inform the user and exit the program. The shipping charges are: Weight of Package Shipping Charge 2 pounds or less $1.25 Over 2 pounds but not more than 6 pounds $2.50 Over 6 pounds but not more than 10...

  • Write a Python program, with comments, to do the following:                        Ask the user to enter...

    Write a Python program, with comments, to do the following:                        Ask the user to enter a string with at least 7 characters. Assume user will enter a valid string. Assign the string to a variable str1 and print str1. In a loop do the following: Update the value of str1 so that the first character from the current value of str1 is removed and added to the end. Print the updated str1.       The loop should continue until updated...

  • Homework 1 - Simple Array Handling Write a working C++ program to ask the user for...

    Homework 1 - Simple Array Handling Write a working C++ program to ask the user for a set of grades which are to be stored in an array in increasing sequence. The user must first provide the number which represents the count of all grades to be provided. For example, if there will be 10 grades, the user is first prompted to provide the number 10. Subsequently, each grade is provided, one at a time. Allow for a maximum of...

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following: Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...

  • This MUST be done in C++ Write a program with a loop to ask the user...

    This MUST be done in C++ Write a program with a loop to ask the user for an integer greater than or equal to 2 and then pass the integer to a function which will produce and display on the console the ulam sequence1. Do not accept a number less than 2. 1The ulam sequence begins with an integer. If it is even, divide by 2. If it is odd, multiply by 3 and add 1. Then apply the appropriate...

  • Write a program in visual c# program named CheckMonth that prompts a user to enter a...

    Write a program in visual c# program named CheckMonth that prompts a user to enter a birth month. If the value entered is greater than 12 or less than 1, display an error message; otherwise, display the valid month with a message such as 3 is a valid month.

  • Write a complete C++ program to ask the user to inter two integers and the program...

    Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Write a complete C++ program to ask the user to inter two integers and the program finds and display the greatest common divisor (GCD) of the two integers. Typical output screen should be as following: Enter two integers 18 27 The GCD is = 9

  • write C++ code ask user 1 for age assign age ask user 2 for age assign...

    write C++ code ask user 1 for age assign age ask user 2 for age assign age Determine who is older Display who is older Add pazzaz.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT