#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Welcome to BOOKAZINEWEB!";
cout << "Books Available in the BOOKAZINE WEB";
cout << setw(3) << "\n A (Ladybird - $15.98)";
cout << setw(3) << "\n B (Sidney Sheldon - $25.50)";
cout << setw(3) << "\n C (Nora Roberts - $28.45)";
cout << setw(3) << "\n D (Penguin Classics - $40.55)";
cout << setw(3) << "\n E (Virginia Andrews - $42.98)";
int counter =0;
int quantity;
int book1;
int book2;
int book3;
int book4;
int book5;
double price1 = 15.98;
double price2 = 25.50;
double price3 = 28.45;
double price4 = 40.55;
double price5 = 42.98;
while (counter != -1 )
{
int choice;
cout << "\nPlease input the letter based on the book type (-1 to checkout)";
cin >> choice;
switch (choice)
{
case 'a':
case 'A':
cout << "Quantity for'Ladybird'?\n";
cin >> quantity;
book1 *= quantity;
price1 *= quantity;
break;
case 'b':
case 'B':
cout << "Quantity for 'Sidney Sheldon'?";
cin >> quantity;
book2 *= quantity;
price2 *= quantity;
break;
case 'c':
case 'C':
cout << "Quantity for 'Nora Roberts'?";
cin >> quantity;
book3 *= quantity;
price3 *= quantity;
break;
case 'd':
case 'D':
cout << "Quantity for 'Penguin Classics'?";
cin >> quantity;
book4 *= quantity;
price4 *= quantity;
break;
case 'e':
case 'E':
cout << "Quantity for 'Virginia Andrews'?";
cin >> quantity;
book5 *= quantity;
price5 *= quantity;
break;
default:
cout << "The letter you entered didn't match the following criteria";
cout << "\n Please enter another letter" << endl;
break;
}
}
}
|
1>------ Build started: Project: ONLINE, Configuration: Debug Win32 ------ 1> ONLINE.cpp 1>c:\users\sony\documents\visual studio 2010\projects\online\online\online.cpp(47): warning C4700: uninitialized local variable 'book1' used 1>c:\users\sony\documents\visual studio 2010\projects\online\online\online.cpp(55): warning C4700: uninitialized local variable 'book2' used 1>c:\users\sony\documents\visual studio 2010\projects\online\online\online.cpp(63): warning C4700: uninitialized local variable 'book3' used 1>c:\users\sony\documents\visual studio 2010\projects\online\online\online.cpp(71): warning C4700: uninitialized local variable 'book4' used 1>c:\users\sony\documents\visual studio 2010\projects\online\online\online.cpp(79): warning C4700: uninitialized local variable 'book5' used 1> ONLINE.vcxproj -> c:\users\sony\documents\visual studio 2010\Projects\ONLINE\Debug\ONLINE.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== |
while (counter != -1) but the value of counter is never changed from 0. (infinite loop)#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Welcome to BOOKAZINEWEB!";
cout << "Books Available in the BOOKAZINE WEB";
cout << setw(3) << "\n 1 (Ladybird - $15.98)";
cout << setw(3) << "\n 2 (Sidney Sheldon - $25.50)";
cout << setw(3) << "\n 3 (Nora Roberts - $28.45)";
cout << setw(3) << "\n 4 (Penguin Classics - $40.55)";
cout << setw(3) << "\n 5 (Virginia Andrews - $42.98)";
int counter =0;
int quantity;
int book1 = 0;
int book2 = 0;
int book3 = 0;
int book4 = 0;
int book5 = 0;
double price1 = 15.98;
double price2 = 25.50;
double price3 = 28.45;
double price4 = 40.55;
double price5 = 42.98;
while (counter != -1 )
{
int choice;
cout << "\nPlease input a number based on the book type (-1 to checkout)";
cin >> choice;
switch (choice)
{
case '1':
cout << "Quantity for'Ladybird'?\n";
cin >> quantity;
book1 *= quantity;
price1 *= quantity;
break;
case '2':
cout << "Quantity for 'Sidney Sheldon'?";
cin >> quantity;
book2 *= quantity;
price2 *= quantity;
break;
case '3':
cout << "Quantity for 'Nora Roberts'?";
cin >> quantity;
book3 *= quantity;
price3 *= quantity;
break;
case '4':
cout << "Quantity for 'Penguin Classics'?";
cin >> quantity;
book4 *= quantity;
price4 *= quantity;
break;
case '5':
cout << "Quantity for 'Virginia Andrews'?";
cin >> quantity;
book5 *= quantity;
price5 *= quantity;
break;
default:
cout << "The number you entered didn't match the following criteria";
cout << "\n Please enter another number" << endl;
break;
}
}
} |
<> symbol)case '1': should be case 1: and so on