can you guys tell me whats wrong with my program?
example outpust should be
"Type a number followed by its multiple: 25 5
Multiples of 5 from 1 to 25: 5 10 15 20 25"
#include <iostream>
usingnamespace std;
void askValues(int num,int mul);
void dispMulitples(int num,int mul);
int main(){
int num,mul;
askValues(num,mul); //ask for the number and multiple value
dispMulitples(num,mul); //displays the multiples(mul) of num
return 0;
}
void askValues(int num,int mul){
cout << "Type a number and multiple value: ";
cin >> num;
cin >> mul;
}
void dispMulitples(int num,int mul){
cout << "Multiples of " << mul << " from 1 to " << num << " ";
for(int i = 1; i <= mul; i++){
cout << i << endl;
}
}
Line 17: pass your parameters by reference so that when you read into them, the values are still available to you when you return to main. Make sure you change the forward declaration on line 4 also. void askValues(int& num, int& mul)
Lines 25-26: Use the stepping interval of the 'for' loop to print your multiples. Start at your multiple number, then increment by that number each time through the loop:
1 2 3 4
for(int i = mul; i <= num; i += mul)
{
std::cout << i << std::endl;
}
#include <iostream>
usingnamespace std;
void askValues(int& num,int& mul);
void dispMulitples(int num,int mul);
int main(){
int num,mul;
askValues(num,mul); //ask for the number and multiple value
dispMulitples(num,mul); //displays the multiples(mul) of num
return 0;
}
void askValues(int& num,int& mul){
cout << "Type a number and multiple value: ";
cin >> num;
cin >> mul;
}
void dispMulitples(int num,int mul){
cout << "Multiples of " << mul << " from 1 to " << num << " ";
for(int i = 1; i <= mul; i++){
cout << i << endl;
}
}