hey i am a 1 st yr college student in my country and im findin c++ programmin 2 b difficult n i found this site n i wud like to know if ne 1 here can help me with these 3 programs?

1. write a program that prompts for and reads a distance in kilometer and output the distance ad mintues.

2. write a program that prompts for and reads a distance in miles and output te distance as kilometers.

3. write a program that computes the number of mintues it takes for light to reach the earth from the sun. You will need to know the speed of light and the distance between the earth and sun.


plz make it as simple as possible for me 2 understan u can email it 2 email removed or post it bak on this ASAP!!! REALLY NNED THIS INFO BY 2NITE THANXZ IN ADVANCE!

We'll certainly help you, but we won't do your work for you. If you have some code that's not working right, post it and we'll try to fix it. If you don't know how to code the solution, tell us what how you think it should be solved and we'll try to help you translate it to code.

Oh, and for #3, you can use this:

#include<iostream>
using namespace std;

int main()
{
        cout << "8.3 minutes" << endl;
}

for #1 i tried this but da compier keeps sayin da erro thing

//program that prompts and read  a distance in Kilometer and ouput the distance in mintues
//Author: Cenica Pattterson
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main()
{
    int Mintues;
    
    
    cout<<"please enter the distance in kiolmeters"<<endl;
    cin>>Kiolometers>>endl;
    cout<<"the distance in mintues is"<<endl;
    system("pause");
    return 0;
}

Honestly im jus startin and i dont kno a shit bout this n codes but i can try 2 explain waht i want to do for 1 i want to input the distance in kilometers 1st it will come up askin for it, then i want to be able to type it in. then i want it to calculate the distance in minutes and output it.

for # 2 same thing

3 now i want to also like for it to input the speed of light and then do the calculations and output it on the screen by askin for the distance between the earth and sun so it can calulate the answer and ouput it!!! im not sure if im makin myself clear plz let me kno....

Let's walk through the code real quick:

#include<iostream>
#include<string>
#include<stdlib.h> // this should be <cstdlib>
using namespace std;
int main()
{
  int Mintues; // where is this used later?  And did you mean miles?
  cout<<"please enter the distance in kiolmeters"<<endl;
  cin>>Kiolometers>>endl; // where is Kilometers defined?
  // you probably should do the conversion here...
  cout<<"the distance in mintues is"<<endl; // you need to output your result here too
  system("pause");
  return 0;
}

You've got the basic idea, but hopefully the comments will get you the rest of the way. For the second problem it's just a matter of switching the words and the conversion factor (from 1.6 to 0.6).

For the last one, do you need to get the distance and the speed from the user, or should you just use constant values? You can approximate the distance as 93 million miles and the speed as 186,000 mi/s if you're just using constants.

Oh, and for #3, you can use this:

#include<iostream>
using namespace std;

int main()
{
        cout << "8.3 minutes" << endl;
}

I don't know about that... most teachers don't want a constant for that type of assignment, they want to see the program actually calculating the result. Even if the output is the same, you'd probably lose marks if you handed it in that way.

for #1 i tried this but da compier keeps sayin da erro thing
//program that prompts and read a distance in Kilometer and ouput the distance in mintues
//Author: Cenica Pattterson
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main()
{
int Mintues;


cout<<"please enter the distance in kiolmeters"<<endl;
cin>>Kiolometers>>endl;
cout<<"the distance in mintues is"<<endl;
system("pause");
return 0;
}

I have 2 points to make. The first is, how in the world are you calculating the distance when you don't have the velocity? I see 3 variables in the problem: time, distance and speed. The problem requests that the user input the distance. But how is the time calculated when the speed in unknown? Maybe I missed something.

The second is that you don't really need the system() call to pause the program at the end. A more portable and faster function is to use the cin.get() command:

cin.get(); // works just as well as system("pause")

But other than that, you're definitely getting there...

#include<iostream>
#include<string>
#include<cstdlib.h> 
using namespace std;
int main()
{
  int Kiolmeters;
  int mintues;
  cout<<"please enter the distance in kiolmeters"<<endl;
  cin>>Kiolometers>>endl;
  cout<<"Kiolmeters to mintues is"<<(Kiolmeters*mintues)<<endl;
  cout<<"the distance in mintues is"<<(Kiolmeters*mintues)<<endl; 
  system("pause");
  return 0;
}

Ok, I think I misunderstood. As joeprogrammer pointed out, if you're supposed to output the time it'll take to travel the given distance, you'll need a speed as well. Then the time will be distance/speed. So you'll need another variable for the speed, and you'll have to input that as well.

okie im totally lost now!

Alright, let's see if we can't start over.

The first problem asks you to write a program where you input the distance and output the "distance as minutes." I'm guessing this means the amount of time to travel the inputted distance. In order to make this calculation, you need a speed. For example, if you're going 10 km, it'll take you longer if your speed is 2km/min than if it's 6km/min. Is this right so far?

okie im totally lost now!

Perhaps it would have been better to post your problems one at a time so to keep focused on a problem. Remember that a program is not simply just using lines of code you've learned; to do something useful you must apply everyday math to the development. I'll try to explain the first one better.

You're trying to find "time", in the context of distance and speed. The formula for time is:
time = distance/speed

So to calculate time, you'll need both speed AND distance. Input them both in, and the plug these into the formula (in C++ this time):

time = distance/speed;

But this formula will only work if distance and speed actually contain values, and not random junk. So you have to get the input from cin and send it to these variables.

Hope this helps

thanxz im tryin 2 figure out the rest if i need nemore help ill let u kno...

thanxz im tryin 2 figure out the rest if i need nemore help ill let u kno...

CPato, did you read the Rules? You definitely need to read the first paragraph of this and this rule.

@CPato:

one more tip:

int Kiolmeters;
[snip]
cin>>Kiolometers>>endl;

You should really be more carefull with typo's Kiolmeters != Kiolometers. These 'tiny' errors can cost you a lot of time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.