need help :problems to be solved

Page 1 of 1

4 Replies - 821 Views - Last Post: 14 November 2008 - 02:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=71934&amp;s=16f1286acdecc0fec252ac59dc19f5da&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 waxrunner

Reputation: 0
• Posts: 5
• Joined: 14-November 08

need help :problems to be solved

Posted 14 November 2008 - 01:18 PM

hello all
i am just new to C programing and in in a need for some help for these problems

1#

Write a program that prompts the user for the area and perimeter of a rectangle. Then it will compute the width and length and display them on the screen (width <= length).
The mathematical relations for area and perimeter of a rectangle are given below.

This problem needs a solution of a quadratic equation. This equation is obtained by finding the expression of length (width) from perimeter equation. Then, you substitute it in area equation. This will give you a quadratic equation in terms of width (length).

2#
Write a program that reads a charactert from the user and prints one of the following messages:
You typed a digit
You typed a capital letter
You typed a small letter
Your typed character is not a letter or a digit

*** i need to know the error in this program
this program does compile

```#include <stdio.h>

int main()
{
printf("1: Convert from miles to kilometers\n");
printf("2: Convert from feets to meters\n");

int choice;

double km ,miles, meters, feets, miles2km , feets2meters;

scanf("%i", &choice);
switch(choice)
{

case 1:
printf("Enter the number of miles to convert to kilometers:\n");
scanf("%lf", &miles);		 [[not performed when running the program]]
miles2km = miles*1.609;

printf("%.2lf miles = %.2lf kilometers\n", miles, miles2km);
break;

case 2:
printf("Enter the number of feets to convert to meters:\n");
scanf("%lf", &feets); [[not performed when running the program]]
feets2meters = feets*0.3048 ;
printf("%.2lf feets = %.2lf meters\n", feets, feets2meters);
break;

default:
printf("wrong input, you need to type 1 or 2.");
break;
}

return 0;
}
```

This post has been edited by Jayman: 14 November 2008 - 02:46 PM

Is This A Good Question/Topic? 0

Replies To: need help :problems to be solved

#2 Gloin

• Expert Schmexpert...

Reputation: 235
• Posts: 4,489
• Joined: 04-August 08

Re: need help :problems to be solved

Posted 14 November 2008 - 01:37 PM

[rules][/rules]

It helps if you can explain what is wrong with your code.
* Does it compile?
* Does it run but you don't get the expected output?
* What is the expected output?

#3 waxrunner

Reputation: 0
• Posts: 5
• Joined: 14-November 08

Re: need help :problems to be solved

Posted 14 November 2008 - 01:54 PM

GLOIN

excuse me for that because a im just new to the forum
i edited my topic
***
my program was to convert from miles to km and from feets to meters

#4 KYA

• yay verily

Reputation: 3155
• Posts: 19,198
• Joined: 14-September 07

Re: need help :problems to be solved

Posted 14 November 2008 - 02:06 PM

Compilation errors are syntax errors.

BTW the program works for me:

```#include <stdio.h>
#include<iostream>

int main()
{
printf("1: Convert from miles to kilometers\n");
printf("2: Convert from feets to meters\n");

int choice;

double km ,miles, meters, feets, miles2km , feets2meters ;

scanf("%i", &choice);
switch(choice)
{

case 1:
printf("Enter the number of miles to convert to kilometers:\n");
scanf("%lf", &miles);
miles2km = miles*1.609 ;

printf("%.2lf miles = %.2lf kilometers\n", miles, miles2km);
break;

case 2:
printf("Enter the number of feets to convert to meters:\n");
scanf("%lf", &feets);
feets2meters = feets*0.3048 ;
printf("%.2lf feets = %.2lf meters\n", feets, feets2meters);
break;

default:
printf("wrong input, you need to type 1 or 2.");
break;
}

int chars;
std::cin >> chars;
return 0 ;
}

```

What is it not doing that you are expecting? (If your code looks like what you pasted then it may be indentation issues). I added some C++ stuff when I tested it, doesn't effect the program, you can easily remove stuff.

This post has been edited by KYA: 14 November 2008 - 02:06 PM

#5 waxrunner

Reputation: 0
• Posts: 5
• Joined: 14-November 08

Re: need help :problems to be solved

Posted 14 November 2008 - 02:23 PM

KYA

thanks for you help

i am going to take my next major exam next wednsday and i am gonna post it after.