While loop problem

Hello all,

I am newbie in C++ programming.Recently i encountered one problem regarding to "while" loop.

The question is like that:

quantity price
10 50
20 100
30 150
40 200
50 250

How to create the above table using "while" loop?
Last edited on
Make an integer variable called "quantity" and have it loop through the values 10, 20, 30, 40, and 50.

Using a for() loop this could be done like:

1
2
for( int quantity = 10; quantity <= 50; quantity += 10 )
   cout << quantity << endl;




char choice = 'x';
int days = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
int tseconds = 0;
//clrscr();

printf("You will asked to enter letter D for days, H for hours, M for minutes and S for seconds:");
printf("\nPress Please enter 'D' for days:");
scanf("%s",&choice);
if (choice == 'D')
{
printf("Enter how many days:");
scanf("%i", &days);
if (days >= 0)
{

Last edited on
1. Write down pseudo code for a switch statement that selects one of four possible values For a variable named salary. The four possible values for salary are 30, 40, 50&60 for Value you must print low. Medium high top respectively
2. Write down the input & output value you would use in a simple desk check procedure to test that you program is working properly



/******************************
Program

* Author your name goes here.
* Date written The date goes here.
* System MS-DOS
* ------------------+
* Function
*
*
*/

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

int main(void)
{


int Low = 30;
int Medium = 40;
int High = 50;
int Top = 60;
int Temp = 0;



printf("Enter the Low integer: ");
scanf("%i",&Low);
printf("Enter the medium integer: ");
scanf("%i",&Medium);
printf("Enter the the high integer : ");
scanf("%i",&High);
printf("\nEnter the top integer: ");
scanf("%i",&Top);

if (Low > Medium)
{
Temp = Low;
Low = Medium;
Medium = Temp;
}
if (Medium > High)
{
Temp = Medium;
Medium = High;
High = Temp;
}
if (High > Top)
{
Temp = High;
High = Top;
Top = Temp;
}
printf("The nembers in ascending order");
printf("are %i%i%i%i%",Low,Medium,High,Top);
printf("n\press Enter to contiue");
/*
*Top is NOW the toppest, just need to get Low, Medium and High
*in the right order
*/
getch();
return 0;
}



2. simple desk check table

step Input variable operation Output variable
1 30 30 = low low
2 40 40 = medium medium
3 50 50 = high High
4 60 60 = Top top
5
6

can any one help with the above 1 & 2 please
tahnks





Last edited on
Kaka, please make a separate thread.

However, you have to make an attempt at answering these questions by posting what you've got so far. We won't just do your homework for you.

is ther any way can one in shorty way thanks

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
Last edited on
// this is the program for printing the above table using while loop
#include<iostream.h>
#include<conio.h>
void main()
{
int quantity=10,price;
cout<<"\n quantity \t price;
while(quantity<=50)
{
price=quantity*5;
cout<<"\n %d \t %d",quantity,price;
quantity=quantity+10;
}
getch();
}
Last edited on
I think a simpler way would be to use setw(), which creates a table like what he wants to do. I forgot exactly how to use it, but I know that it is specifically helpful for use with turning a for loop into an organized table.
Topic archived. No new replies allowed.