Welcome! Log In Create A New Profile

Advanced

COS111-U lesson 4(assignment vriables)

Posted by london 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
COS111-U lesson 4(assignment vriables)
March 23, 2007 11:52AM
Please help me out with Subactivity 4.a.1.
#include <iostream>
using namespace std;

int main()
{
int hours1, hours2, mins1, mins2, totalHours, totalMins;
cout << "Enter the time in hours and minutes: ";
cin >> hours1 >> mins1;
cout << "Enter another time in hours and minutes: ";
totalHours = hours1 + hours2;
totalMins = mins1 + mins2;
cin >> hours2 >> mins2;
cout << "The total time is " << totalHours << " hours and " << mins1 +
mins2 << " minutes" << endl;
return 0;
}

the programme compiles but when i run it, it gives me a wrong number of hours(4000869). The minutes are calculated correctly but the hours just don't want to.

Please help since i need to finish this before tuesday so that i can submitt my assignment( Due on 30 March)

please email me on m26435@yahoo.co.uk or n290988m@gmail.com
or send me an sms on 078 415 5547.
Later
Re: COS111-U lesson 4(assignment vriables)
March 23, 2007 12:51PM
Your statement cin >> hours2 >> mins2; is in the wrong place, it should come directly after the cout << "Enter another time in hours and minutes: "; statement, otherwise you are adding a known variable to an unknown variable.

D
Re: COS111-U lesson 4(assignment vriables)
March 29, 2007 12:21PM
Thanks alot Doug I appreciate it. You were right i had the assignment statement in the wrong place.
Sorry, only registered users may post in this forum.

Click here to login