1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid”
2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid”
3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars. Use the discount table below:
Example: If the user enters 15, they should pay 15*10 – (5/100)*15*10 = 142.50 dollars
Quantity |
Discount |
1-10 |
No Discount |
11-20 |
5% |
21-50 |
10% |
Above 50 |
15% |
4)Ask a user to input two numbers and print out the smaller number. If the numbers are equal, print out that the numbers are equal.
1)
Progarm :
#include <iostream>
using namespace std;
int main()
{
int number; // variable declaration
cout << "Enter a number : ";
cin>>number; // Accept number
if(number>0) // check number is greater than 0
cout << "The number is valid" << endl;
else
cout << "The number is invalid" << endl;
return 0;
}
Output :
2)
#include <iostream>
using namespace std;
int main()
{
int grade; // variable declaration
cout << "Enter a grade : ";
cin>>grade; // Accept grade
if(grade>0&&grade<101) // check grade in between
0-101
cout << "The grade is valid" << endl;
else
cout << "The grade is invalid" << endl;
return 0;
}
Output :
Get Answers For Free
Most questions answered within 1 hours.