Unexplainable funny error, LOL!
Jan 31, 2012 at 9:11am UTC
I'm doing this programming exercise were the following series of actions happen:
"Enter the number of hours: 3
"Enter the number of minutes:45
Time: 3 hours 45 minutes
And this was the code. It wouldn't compile due to a error I constanly get "Expected primary expression before "void""
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
using namespace std;
void tt();
int totalhours, totalminutes;
int main()
{
cout << "Enter the number of hours: " ;
cin >> totalhours;
cout << "Enter the number of minutes: " ;
cin >> totalminutes;
cout << " Time: " << tt(void );
system("PAUSE" );
return 0;
}
void tt()
{
cout << totalhours << ":" << totalminutes;
}
So I tried to change the return type of "tt" to int. New Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
using namespace std;
int tt();
int totalhours, totalminutes;
int main()
{
cout << "Enter the number of hours: " ;
cin >> totalhours;
cout << "Enter the number of minutes: " ;
cin >> totalminutes;
cout << " Time: " << tt();
system("PAUSE" );
return 0;
}
int tt()
{
cout << totalhours << ":" << totalminutes;
}
And this is the output:
"Enter the number of hours: 3
"Enter the number of minutes:45
3:45 Time: 4469712
Were the hell did the 4469712 code come from? And can anyone help me find a solution to my original code? Thx!
Jan 31, 2012 at 9:44am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
using namespace std;
void tt();
int totalhours, totalminutes;
int main()
{
cout << "Enter the number of hours: " ;
cin >> totalhours;
cout << "Enter the number of minutes: " ;
cin >> totalminutes;
cout << " Time: " ;
tt();
return 0;
}
void tt()
{
cout << totalhours << ":" << totalminutes;
}
I fixed your original code up, so it should work :D.
Jan 31, 2012 at 10:15am UTC
Were the hell did the 4469712 code come from?
It came from
tt() . tt() is retuning an uninitialized int, you compiler should have told you that. If it didn't then you should look at changing your compiler, if it did and you ignored it then...Do
NOT ignore warnings, fix them.
Topic archived. No new replies allowed.