I just started my first c++ class and we recieved our first assignment.
I dont have a compiler at home and live far away from school.
I have 2 questions:
These are the program requirements:

Program 1:

Prompt the user and let them enter three integers. Store them in three variables. Print the numbers in sorted order, from smallest to largest.

Sample run: (user input underlined)

Input integer 1 : 34
Input integer 2 : 200
Input integer 3 : -14

Sorted : -14 <= 34 <= 200

This is the code:

#include <iostream>


int main ( )
{


int one, two, three, first, sec, third;


cout << "Enter 3 integers./n";
cout << "Input Integer 1 : ";
cin  >> one;
cout << "/nInput Integer 2 : ";
cin  >> two;
cout << "/nInput Integer 3 : ";
cin  >> three;


if ( one >= two && one >= three)
one == first;
if ( two >= one && two >= three)
two == first;
if ( three >= one && three >= two)
three = first;


if (one <= two && one >= three)
one == sec;
if (one >= two && one <= three)
one == sec;
if (two <= one && two >= three)
two == sec;
if (two >= one && two <= three)
two == sec;
if (three <= two && three >= one)
three == sec;
if (three >= two && three <= one)
three == sec;


if (one <= two && one <= three)
one = third;
if (two <= one && two <= three)
two = third;
if (three <= one && three <= two)
three = third;


cout << first << ">=" << sec << ">=" << third << ".";
cout << "Have a Nice Day!";


}

Will it work? Any changes(Im sure there is another way without all those ifs.

Program 2 requirments:

Prompt the user to type an integer in the range 0 - 1000. Allow the user to input an integer (you may assume correct type of input. Whenever the integer is not in the specified range, print an error message and make the user re-enter. Once a valid input is received, compute and print out the sum of the digits of the number.

Sample run 1: (user input underlined)

Please input an integer between 0 and 1000: 1001
* Number not in 0-1000 range. Please re-enter: -1
* Number not in 0-1000 range. Please re-enter: 456

Sum of the digits is 15

Code:

#include <iostream>


int main( )
{


int;
cout << "Enter an integer between and including 0-1000./n";
cin   >> num;


if (num < 0  ||  num > 1000)
{
cout << "Number not between 0-1000./n";
cout << "Enter an integer between and including 0-1000./n";
cin   >> num;
}


num1 = num / 100
num2 = (num % 100) / 100
num3 = (num % 100) % 10


cout << The sum of the digits is : ;
cout << num1 + num2 + num3


}

Thanks for any help you can provide, email me at rymade@yahoo.com

Your first program is too big.

Something like:

#include <stdio.h>

void Swap(int *first,int *second) {
*first ^= second;
*second ^= first;
*first ^= second;
}
int main(void) {
int numbers[4];
for (int temp = 0;temp<3;temp++) scanf("%d",&numbers[temp]);
for (temp=0;temp<2;temp++) {
if (numbers[temp] > numbers[temp+1] )
Swap(&numbers[temp],&numbers[temp+1]);
}
if (numbers[0] > numbers[1]) Swap(&numbers[0],&numbers[1];
return 0;
}

You said that was your first assignment, so I'm not sure you know how to use functions and whatnot, but the program I made should work. Post back any problems.

As for your second:

#include <stdio.h>

int main(void) {
int temp = -1;
while (temp < 0 || temp > 1) {
printf("Input number:\n");
scanf("%d",&temp);
}
for (temp2 = 0;temp;temp/=10) temp2+=temp%10;
printf("%d",temp2);
return 0;
}

Now then, I thought of these from my head. I didn't compile em', but post back with any errors you might have, and I can fix em'.

heh no offense but i dont think you wan to get his teachers hopes up that he knows #include <stdio.h>
it will get all confusing later if you try to switch between #include <iostream> and #include <stdio.h>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.