+ 2
Two questions in C++ need help with.
1. Design a logic for a program That allows the user to enter 20 then display them in the reverse order of entry? 2. Modify the reverse display program so that the user can enter any amount of numbers up 20 until a sentinel value is entered?
7 Respuestas
+ 5
logic 1
cin>>n;
//where n=20
while(n!=0)
{
cout<<n;
n—;
}
explain logic 2 its not clear
+ 2
Thank you to both of your suggestions, I will try to write the code using an array. I am taking my first programing class intro into programming 120. I can honestly say I am clueless when it comes to coding but I want to understand it and am eager to learn how!
+ 1
Have you tried to write the code? If yes then tell what problems you are facing.
+ 1
Display 20 what? 20 ints? 20 chars? I can give you a hint. Use an array.
+ 1
/*
Enter two numbers
This program lists all the numbers from the lowest entered to the highest entered in rows of ten
*/
#include <iostream>
using namespace std;
int main() {
int v1,v2;
cin>>v1>>v2;
int lower,higher;
if(v1<v2)
{
lower=v1;
higher=v2;
}
else
{
lower= v2;
higher= v1;
}
int i = 0;
while(lower<=higher)
{
if(i<=9)
{
cout<<lower<< " ";
i++;
}
else
{
cout<< endl<<lower<< " ";
i=1;
}
lower++;
}
return 0;
}
+ 1
thank u for the answer, Divij. sorry it took me so long to respond back.
0
Besides solo learn, cplusplus.com and theCherno on youtube are great sources to learn C++. Cheers