School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,477 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,763 people online right now. Registration is fast and FREE... Join Now!




Simple Microsoft Visual C++ Program

 

Simple Microsoft Visual C++ Program, Distance traveled by a car

Bruce_d39

25 Apr, 2009 - 07:50 AM
Post #1

New D.I.C Head
*

Joined: 24 Apr, 2009
Posts: 12

Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. the program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output:

What is the speed of the vehicle in Mph? 40
How many hours has it traveled? 3
Hour Distance Traveled
---------------------------------------
1 40
2 80
3 120

Input Validation: Do not accept a negative number for speed and do not accept any value less than 1 for time traveled.

I am willing to pay $40 through paypal account.
Thanks

Bruce

This post has been edited by Bruce_d39: 25 Apr, 2009 - 07:57 AM

User is offlineProfile CardPM
+Quote Post


tommyflint

RE: Simple Microsoft Visual C++ Program

25 Apr, 2009 - 11:53 AM
Post #2

D.I.C Addict
Group Icon

Joined: 24 Jul, 2008
Posts: 584



Thanked: 28 times
My Contributions
Hey Bruce,

I know this isn't the language you asked for it in but i have done it in VB.Net and you more than welcome to have it free of charge as it is only a couple lines of code?
I would of done it in C# but i dont know it lol

Cheers,

Tommyflint
User is offlineProfile CardPM
+Quote Post

Core

RE: Simple Microsoft Visual C++ Program

25 Apr, 2009 - 12:15 PM
Post #3

Den The Developer
Group Icon

Joined: 8 Dec, 2008
Posts: 2,944



Thanked: 214 times
Dream Kudos: 900
Expert In: C#, VB.NET, .NET Framework

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is offlineProfile CardPM
+Quote Post

Bruce_d39

RE: Simple Microsoft Visual C++ Program

25 Apr, 2009 - 02:28 PM
Post #4

New D.I.C Head
*

Joined: 24 Apr, 2009
Posts: 12

QUOTE(tommyflint @ 25 Apr, 2009 - 11:53 AM) *

Hey Bruce,

I know this isn't the language you asked for it in but i have done it in VB.Net and you more than welcome to have it free of charge as it is only a couple lines of code?
I would of done it in C# but i dont know it lol

Cheers,

Tommyflint


Hello! Sure if you don't mind I would like the code. Thanks so much!

Bruce
User is offlineProfile CardPM
+Quote Post

tommyflint

RE: Simple Microsoft Visual C++ Program

25 Apr, 2009 - 03:12 PM
Post #5

D.I.C Addict
Group Icon

Joined: 24 Jul, 2008
Posts: 584



Thanked: 28 times
My Contributions
Hey,

Yeah no problem... i will leave all the controls named to the default name so it more clear. If you need any help with the code don't hestiate to ask.
The form just has 5 controls MPH Textbox.... Hours Textbox..... List Box.... Total TextBox and a button.
CODE

Public Class Form1

Private Sub Button1_Click(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MPH As Integer
Dim Hours As Integer
Dim I As Integer = 0
Dim Miles As Integer
Dim Total As Integer

MPH = Int32.Parse(TextBox1.Text)
Hours = Int32.Parse(TextBox2.Text)
ListBox1.Items.Clear()

Do Until I = Hours
        Miles += MPH
        ListBox1.Items.Add(I + 1 & " - " & Miles)
        i += 1
Loop

Total = MPH * Hours
TextBox3.Text = Total

End Sub
End Class


If it fails just check the syntax and spellings as i had to retype it as i did the program on my other PC.

If you have question dont hesiate to ask.

Cheers,

Tommyflint

This post has been edited by tommyflint: 25 Apr, 2009 - 03:14 PM
User is offlineProfile CardPM
+Quote Post

Bruce_d39

RE: Simple Microsoft Visual C++ Program

25 Apr, 2009 - 04:10 PM
Post #6

New D.I.C Head
*

Joined: 24 Apr, 2009
Posts: 12

QUOTE(tommyflint @ 25 Apr, 2009 - 03:12 PM) *

Hey,

Yeah no problem... i will leave all the controls named to the default name so it more clear. If you need any help with the code don't hestiate to ask.
The form just has 5 controls MPH Textbox.... Hours Textbox..... List Box.... Total TextBox and a button.
CODE

Public Class Form1

Private Sub Button1_Click(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MPH As Integer
Dim Hours As Integer
Dim I As Integer = 0
Dim Miles As Integer
Dim Total As Integer

MPH = Int32.Parse(TextBox1.Text)
Hours = Int32.Parse(TextBox2.Text)
ListBox1.Items.Clear()

Do Until I = Hours
        Miles += MPH
        ListBox1.Items.Add(I + 1 & " - " & Miles)
        i += 1
Loop

Total = MPH * Hours
TextBox3.Text = Total

End Sub
End Class


If it fails just check the syntax and spellings as i had to retype it as i did the program on my other PC.

If you have question dont hesiate to ask.

Cheers,

Tommyflint


Thanks for your help!
Bruce

User is offlineProfile CardPM
+Quote Post

thursdayniac

RE: Simple Microsoft Visual C++ Program

28 Apr, 2009 - 01:31 AM
Post #7

D.I.C Head
**

Joined: 26 Apr, 2009
Posts: 108



Thanked: 3 times
My Contributions
here it is in C++ if you still need it

CODE

#include <iostream>

using namespace std;

int main()
{
    int speed, hours;
    
    cout << "What is the speed of the vehicle in MPH" << endl;
    cin >> speed;
    
    cout << "How many hours has it traveled" << endl;
    cin >> hours;
    
    cout << "Hours   Distance\n"
         << "--------------------" << endl;
        
    for(int i = 1; i <= hours; i++)
         cout << i << "\t" << speed*i << endl;
    system("pause");
}

User is offlineProfile CardPM
+Quote Post

DingleNutZ

RE: Simple Microsoft Visual C++ Program

3 May, 2009 - 02:35 PM
Post #8

D.I.C Head
**

Joined: 2 May, 2009
Posts: 113



Thanked: 1 times
My Contributions
i cant be bothered doing the work, can i still get the $40?

This post has been edited by DingleNutZ: 3 May, 2009 - 02:35 PM
User is offlineProfile CardPM
+Quote Post

MarioKnight368

RE: Simple Microsoft Visual C++ Program

14 Jun, 2009 - 02:45 PM
Post #9

New D.I.C Head
*

Joined: 14 Jun, 2009
Posts: 21



Thanked: 2 times
My Contributions
Here's one that's bascially the same as thursdayniac's, but which has the input validation:

CODE

#include <iostream>

using namespace std;

int main()
{
    int speed = 0;
    int hours = 0;
  
    do {
        cout << "What is the speed of the vehicle in MPH?" << endl;
        cin >> speed;
    }
    while (speed < 0);


    do {
    cout << "How many hours has it traveled?" << endl;
    cin >> hours;
    }
    while (hours < 1);
    
    cout << "Hours   Distance\n" << "--------------------" << endl;
        
    for(int i = 1; i <= hours; i++)
         cout << i << "\t" << speed*i << endl;
    system("pause");
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:37AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month