I Need help with this guys

Please Help me solve this......
C++

A travel group travelled to 5 cities. The
group started its journey from city A and ended at city A. From A it travelled
to city B, from B to city C, from C to city D, from D to city E and form E back
to city A. The distance between two cities are to be provided by the user of
your program. Also, user will provide the total duration of the trip. Write a
program to calculate the total distance travelled by the group and the average
speed for the trip?
Here is an example of the output. User inputs
are given in bold.
What is the distance between cities A and B
(in miles) : 200.6
What is distance between B and C (in miles) : 100.6
What is distance between C and D (in miles) : 150.3
What is distance between D and E (in miles) : 100.1
What is distance between E and A (in miles) : 250.5
What is the total trip (in hours) : 16.3
The total distance travelled is: ? (To be calculated)
Average speed (miles/hr): ? (To be calculated)
What have you written so far? This is just basic stream I/O and some elementary school math.
it is just the introduction to c++
we are writing it using microsoft visual studio 2010 c++
Post what you have written so far [code]between code tags[/code] so that we can help you further. If you don't even know how to start, the hello-world program is a good template. See also, the tutorial on this site:
http://www.cplusplus.com/doc/tutorial/
Last edited on
//Distance in cities
#include <iostream>
using namespace std;
int main ()
{
"distance between cities A and B : 200.6
"distance between B and C : 100.6
"distance between C and D : 150.3
"distance between D and E : 100.1
"distance between E and A : 250.5

I don't know if its the right way
Please edit your post and put your code [code]between code tags[/code]

You misread the assignment. The bolded parts (the numbers) are input given by the user, your program does not know about those numbers in advance.

Also, recall the syntax of an output statement as shown in the hello world program.
Last edited on
help me then because i dont know how to do it
Find the hello world program:
http://www.cplusplus.com/doc/tutorial/

Copy and paste it.

Edit it.

When you get stuck, post the code you currently have [code]between code tags[/code] so that we can help you further.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
//Distance in cities
#include <iostream>
using namespace std;
int main ()
{
"distance between cities A and B : 200.6
"distance between B and C : 100.6
"distance between C and D : 150.3
"distance between D and E : 100.1
"distance between E and A : 250.5 



Start with something like this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
int main ()
{
  double a = 0;
  cout <<"Enter the distance between cities A and B : "<< endl;
  cin >> a;

  return 0;
}
Last edited on
// distance travelled
#include <iostream>
using namespace std;

int main ()
{
int a, b,c,d,e;
a = 200.6 ;
b = 100.6 ;
c = 150.3 ;
d = 100.1 ;
e = 250.5 ;
int totaldistance; a + b + c + d + e;

cout << " int total distance:";

return 0;
}
kemort gave you something you can copy, paste, and edit. Why did you ignore it?
Last edited on
i have done it as you said Mr Kermot below here it is

//Distance in cities
#include <iostream>
using namespace std;
int main ()
{
double a = 0;
cout <<"distance between cities A and B : 200.6 "<< endl;
cin >> a;
cout <<" between cities B and C :100.6 "<< endl;
cin >> a;
cout <<" between cities C and D :150.3 "<< endl;
cin >> a;
cout <<" between cities D and E :100.1 "<< endl;
cin >> a;
cout <<" between cities E and A :250.5 "<< endl;
cin >> a;
return 0;
is that correct?
You will want to store each distance in a different variable. Also, do not include the numbers in the prompt - the numbers are what the user types in, and should not exist in your code.
could you please demonstrate for me
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
    std::cout << "Enter the distance between cities A and B: " << std::endl;
    double a_to_b = 0;
    cin >> a_to_b;

    std::cout << "Enter the distance between cities B and C: " << std::endl;
    double b_to_c = 0;
    cin >> b_to_c;

    //...
}
By the way, you can get the fancy formatting by putting your code [code]between code tags[/code] - it helps a lot because it shows indentation and line numbers.
Last edited on
Topic archived. No new replies allowed.