plz can you help me in solving these two questions

Write your question here.

1. Suppose that the cost of sending an international fax is calculated as follows: Service charges $3.00; $0.20 per page for the first 10 pages; and $0.10 for each additional page. If the number of pages to be faxed is more than 100, the discounted rates are: Service charges $1.00; $0.15 per page for the first 10 pages; and $0.05 for each additional page. Design a program that asks the user to enter the number of pages to be faxed. The program then uses the number of pages to be faxed to calculate the amount due.


2. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle.

Put the code you need help with here.
using if and else

thank u
closed account (o3hC5Di1)
Hi there,

These seem like homework questions. Please note that per the forum rules we do not solve homework for you, but rather try to help you to solve it on your own. So, let's break down the relevant parts of the assignment:

Question 1:

Design a program that asks the user to enter the number of pages to be faxed


You will need to ask the user for input, and store that input into a variable (page_num):
http://www.cplusplus.com/doc/tutorial/basic_io/

The program then uses the number of pages to be faxed to calculate the amount due. [...] Service charges $3.00; $0.20 per page for the first 10 pages; and $0.10 for each additional page. If the number of pages to be faxed is more than 100, the discounted rates are: Service charges $1.00; $0.15 per page for the first 10 pages; and $0.05 for each additional page


This is simple if/else stuff, I could rephrase the question as such:

If page_num is higher than 100, total cost increases by 1$ service cost. Additionally, if the number of pages is more than ten, increase total cost by 10*0.15+0.05*(page_num-10), else (if the number of pages is lower than 10, increase total cost by page_num*0.15.

Else, if page_num is smaller than 100, total cost increases by 3$ service cost. Additionally, if the number of pages is more than ten, increase total cost by 10*0.20+0.10*(page_num-10), else (if the number of pages is lower than 10, increase total cost by page_num*0.20.



Question 2

Write a program that prompts the user to enter the lengths of three sides of a triangle


You should be able to do so with the link provided above for q1.

and then outputs a message indicating whether the triangle is a right triangle. [...] In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides.


Use the data received from the user for this calculation and print to the screen whether it is a right triangle or not.

Please make a fair attempt at starting on this yourself and feel free to come back to us with some of your code if you encounter any issues.

All the best,
NwN
i really did try to solve it by my self its just for check..i solved the second question .. but for the first one there is something wrong

#include<iostream>
using namespace std;
int main()
{
float pages,Tcost;

cout<<"please enter number of pages"<<endl;
cin>>pages;

if (pages<=10)
Tcost=3+pages*0.2;

else

if (10<pages<=100)
Tcost=3+10*0.2+(pages-10)*0.1;

else
Tcost=1+0.15*10+(pages-10)*0.05;

cout<<"Total cost is: "<<Tcost;

return 0;

}
closed account (o3hC5Di1)
Hi there,

Please wrap your code in [code][/code]-tags, it makes it a little more readable.
As for your problem, it's just your lack of using curly braces:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
using namespace std;

int main()
{
    float pages,Tcost;

    cout<<"please enter number of pages"<<endl;
    cin>>pages;

    if (pages<=10)
    { //need curly brace here
        Tcost=3+pages*0.2;
    }//need curly brace here
    else
    {//need curly brace here
        if (10<pages<=100)
            Tcost=3+10*0.2+(pages-10)*0.1;

        else
            Tcost=1+0.15*10+(pages-10)*0.05;
    }//need curly brace here

    cout<<"Total cost is: "<<Tcost;

    return 0;
} 


When either the if or else block contains more than one statement, you are required to use curly braces. Only when both only execute one single statement you can omit them for brevity.

All the best,
NwN
Topic archived. No new replies allowed.