I Need help with this guys

Sep 16, 2014 at 1:43pm
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)
Sep 16, 2014 at 1:50pm
What have you written so far? This is just basic stream I/O and some elementary school math.
Sep 16, 2014 at 1:57pm
it is just the introduction to c++
Sep 16, 2014 at 1:57pm
we are writing it using microsoft visual studio 2010 c++
Sep 16, 2014 at 1:58pm
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 Sep 16, 2014 at 1:59pm
Sep 16, 2014 at 2:06pm
//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
Sep 16, 2014 at 2:18pm
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 Sep 16, 2014 at 2:19pm
Sep 16, 2014 at 5:22pm
help me then because i dont know how to do it
Sep 16, 2014 at 5:31pm
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.
Sep 17, 2014 at 2:23am
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 Sep 17, 2014 at 2:27am
Sep 17, 2014 at 2:43am
// 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;
}
Sep 17, 2014 at 2:50am
kemort gave you something you can copy, paste, and edit. Why did you ignore it?
Last edited on Sep 17, 2014 at 2:50am
Sep 17, 2014 at 3:03am
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;
Sep 17, 2014 at 3:03am
is that correct?
Sep 17, 2014 at 3:07am
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.
Sep 17, 2014 at 3:09am
could you please demonstrate for me
Sep 17, 2014 at 3:11am
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 Sep 17, 2014 at 3:12am
Topic archived. No new replies allowed.