Difference between 4 numbers

Hi,
am very new to c++, in school i was given a couple of assignments and i really dont know how to go about it.

question1
write a program that reads four numbers and find the largest and print the day of the week that corresponds to the number

question2
write a program which reads the average of two numbers and also print the remainder of the second number when divided by the first number

thank you very much!
One program at a time. One step at a time.

Question 1:
1
2
3
4
5
6
7
8
9
10
// Declare variables to store inputs
// Declare an array of strings representing each day
// Start for loop
// -- Ask user for variable input
// -- Start while loop, while input isn't valid
// -- -- Ask for input again
// -- End while loop
// End for loop
// Write simple algorithm to work out highest number
// Print out the string array at the index of that number - 1 


Make sure the user doesn't input something stupid. Presumably, the only numbers that should be entered are between 1 and 7, yes?

Don't forget, arrays start at index 0, if a user enters "1", array index 1 would actually be Tuesday, not Monday. Don't forget to subtract one from the entered number to get the correct day.
Last edited on
Question 2:

1
2
3
4
cin << num1;
cin << num2;
int sum = num1 + num2;
int remain = num2 % num1;
Couple of errors there, captacha. And it doesn't do what the question asks.

I would also refrain from posting code. Since it's classwork, best to give the OP the opportunity to try it themselves.
Last edited on
thanks for the replies.
ihutch
thanks for replies. ihutch pls I need codes as I no nothing about c++ and I have deadline Friday. if I don't get it , I won't be allowed to partake in subsequent classes. pls
thanks
Hi iHutch105,

thanks for the help. i have done some for myself but i am lost

here is what i did so far, pls help improve.

thanks

#include <iostream>

int main()
{
// declaring variables to store inputs:

using namespace std;

int i, j, k, l;

cout << "Please enter a number...\n";
cin >> i;
cout << "And another...\n";
cin >> j;
cout << "And one more...\n";
cin >> k;
cout << "And one more...\n";
cin >> l;
cout << "Thank you!\n";

if (i > j)
{
if (i > l)
cout << i << endl;
}
if (j > k)
{
if (j > i)
cout << j << endl;
}

if (k > l)
{
if (k > j)
cout << k << endl;
}


if (l > i)
{
if (l > k)
cout << l << endl;
}


char response;
cin >> response;
return 0;
}

//declaring an array of strings representing each day

int DayOfWeek [] ={Sunday, Monday, Tuesday, Wednesday};

// starting a loop

Ok, so the inputs are fine but you haven't been clear on the specifics. Do you want the numbers input to be only between 1 and 7? How else are they going to correspond to days of the week if not?

One other thing concerning the inputs; why not make them an array? This would make your input loop so much simpler.

1
2
3
4
5
6
7
8
const int MAX_INPUTS;
int inputs[MAX_INPUTS];

for (int i=0; i < MAX_INPUTS; i++)
{
   cout << "Please enter a number: ";
   cin >> inputs[i];
}


As I said, you may want to include some validation that checks what numbers get entered.

Having that array will make finding the largest number super easy.

1
2
3
4
5
6
7
int largest=0;

for (int j=0; j< MAX_INPUTS; j++)
{
   // Check to see number at that array is larger than largest int
   // then assign accordingly
}


Also, your array of days:
 
string Days[7] = {"Sunday", /*etc*/};


Much happier to help out when you have a go yourself. Haven't given you complete answers there because it's best you learn yourself but hopefully that'll nudge you in the right direction.
thanks ihutch a zillion dozen times. wil try and do something wit wat u given so far.
Topic archived. No new replies allowed.