4 Replies - 757 Views - Last Post: 14 November 2008 - 02:23 PM Rate Topic: -----

#1 waxrunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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("please type your choice (1 or 2):\n");
		 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  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 waxrunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3122
  • View blog
  • Posts: 19,167
  • 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("please type your choice (1 or 2):\n");
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

Was This Post Helpful? 0
  • +
  • -

#5 waxrunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1